0

I'm not quite sure how to click on a div that shows when after you click on the parent..? Make sense?

Here is an example code snippet.

$('.item').bind('click', function(e){
var showme = $(this).find(".itemcontrols");
$(showme).toggle();
}); 

$('#add').bind('click', function(e){
alert();
});     

<div class="item ui-state-default">
    <div class="itemcontrols" style="display: block;">
        <div id="add">add</div>
        <div id="full">full</div>
        <div id="del">del</div>
    </div>
</div>

.item{display:none;}
3
  • I'm trying to click on the #add div but the parent div has a toggle show hide on it. Commented Nov 29, 2012 at 18:33
  • It is not clear what you are trying to achieve.. The code as such looks fine.. Can you be little more specific on which div and what is expected? Commented Nov 29, 2012 at 18:34
  • this will help you : api.jquery.com/event.stopPropagation Commented Nov 29, 2012 at 18:37

1 Answer 1

1

You could add an .itemcontrol class to the children of .itemcontrols.

<div class="item ui-state-default">
  <div class="itemcontrols">
    ...
    <div id="add" class="itemcontrol">add</div>
    ...
  </div>
</div>​

And stop the propagation of all .itemcontrol elements using the .stopPropagation() function.

$('.itemcontrols .itemcontrol').on('click', function(e) {
  e.stopPropagation();
});​

Apart from this, I would recommend you to use .on to bind events, which is the current recommended way.

$('.item').on('click', function(e) {
  $(".itemcontrols", this).toggle();
});

$('.itemcontrols .itemcontrol').on('click', function(evt) {
  evt.stopPropagation();
});​

See it live here.

Sign up to request clarification or add additional context in comments.

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.