我有这样的事情:
<div class='span6'>
<div class='row-fluid'>
<div class='span2 search'>
<img src='img.png'/> <!-- when clicked -->
</div>
<div class='span10'>
<div class='name-info' id="test"> <!-- get this id -->
<h4 class="name"><?php echo $name;?></h4>
<div class='address'>
<?php echo $location;?>
</div>
</div> <!-- end name-info -->
</div>
</div> <!-- end name-block -->
</div>
<div class='span6'>
<div class='row-fluid'>
<div class='span2 search'>
<img src='img.png'/> <!-- when clicked -->
</div>
<div class='span10'>
<div class='name-info' id="test"> <!-- get this id -->
<h4 class="name"><?php echo $name;?></h4>
<div class='address'>
<?php echo $location;?>
</div>
</div> <!-- end name-info -->
</div>
</div> <!-- end name-block -->
</div>
$('.search img').on('click',function(){
alert($(this).next('.name-info').attr("id"));
});
我有两个确切的 div,我正在尝试单击一个 img,当我单击图像时,它应该能够获取 class 的 id,name-info
我该怎么做?我尝试了一些函数,但不熟悉所有 jQuery 函数。请问需要帮助吗?
谢谢!