Problem selecting element with jQuery
This code makes one comment box:
<div class="com_box">
<div class="com_box">
<div class="com_box_text"> text </div>
</div>
</div>
<div class="com_box_info">
<img ...开发者_运维技巧 />
<div> ... </div>
<div>
<a href="" id="quote"> text </a>
</div>
</div>
When i click a#quote i want to do something with the div.com_box_text over. How do i select it with jQuery?
Try something like this:
$(document).ready(function() {
$("#quote").click(function() {
$(".com_box_tex").html("foo");
});
});
$("#quote").click(
function(){
var info_box = $(this).closest(".com_box_text");
// do stuff with info_box
}
);
Edit: I'm assuming you mean you wanted to do something with the nearest instance of that class, not with all elements of that class.
$(document).ready(function() {
$("#qoute").click(function(
$(".com_box_text").hide(); //or something else ;)
));
});
精彩评论