0

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?

1
  • For clarification, will the code you show here appear more than one time on the page? Is this an example of a repeated list of comments? I ask because if a#quote appears more than 1 time on the page you will get funky jQuery results because you all id attributes on the page must be unique. (I apologize if I am barking up the wrong tree). Commented Mar 9, 2010 at 15:02

3 Answers 3

1

Try something like this:

$(document).ready(function() {
    $("#quote").click(function() {
        $(".com_box_tex").html("foo");
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1
$("#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.

Comments

1
$(document).ready(function() {
    $("#qoute").click(function(
       $(".com_box_text").hide(); //or something else ;)
    ));
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.