开发者

Problem selecting element with jQuery

开发者 https://www.devze.com 2022-12-22 14:46 出处:网络
This code makes one comment box: <div class=\"com_box\"> <div class=\"com_box\"> <div class=\"com_box_text\"> text </div>

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 ;)
    ));
});
0

精彩评论

暂无评论...
验证码 换一张
取 消