在链接上获取Div ID单击

时间:2014-05-14 05:33:45

标签: javascript jquery html click fadeout

我想要做的是在点击该框的十字架后淡出一个框但是看起来甚至通过谷歌搜索它仍然可以工作当我通过使用点击它自己来使用它$(这个)但我希望它在单击十字架时起作用。

<?php 
require "global.php";
$select_staff = mysqli_query($database_connection,"SELECT * FROM staff_info");

if(!$select_staff) {
die("Database Error");
}

while($staff_info = mysqli_fetch_array($select_staff)) {
$div_id = $staff_info['div_id']; // assuming you have an id field in your DB
$account_name = $staff_info['account_name'];
$position = $staff_info['position'];
$description = $staff_info['description'];
echo "

<div class='staff_boxes' id='staff_boxes_$div_id'> 
 <a href='#' class='delete_button'> X </a>";
echo"
<h2>$account_name</h2>
$position
<p>$description</p>
</div> ";
}
?>

<script>
$( document ).ready(function() {




$('div').click(function() {
var myScript = document.getElementById('myScript');
 $(this).removeAttr('id').fadeOut();
 });








});
</script>








<style>

.staff_boxes {
width: 250px;
min-height: 150px;
border: 4px solid gold;
background:#C2DAD7;
/*to reduce float drop issues in IE*/
word-wrap: break-word;
}

.staff_boxes {
margin-left: 63px;
float: left;
}



/**Clear floats after the boxes**/

</style>

由于

1 个答案:

答案 0 :(得分:1)

如此定位父母:

$('.delete_button').click(function() {
    $(this).parent().fadeOut();
    return false; //Without this the browser may scroll to the top of the page
});