Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delegate jquery - get parent container

Tags:

jquery

I want to select all p elements in .section container, but just in the one that contains the a.open link that has been clicked

$('.section').delegate('a.open', "click", function(){
    $(this).parent().filter('p').show(); //I want to select all `p` elements in .section container, but just in th one that containts the a.open link that has been clicked
})

Thanks

like image 556
simPod Avatar asked Nov 27 '25 16:11

simPod


1 Answers

You could pass the delegateTarget as context (delegateTarget is a property of the event object which is passed to handler function and is the DOM element which "Handles" the delegation

$('.section').delegate('a.open', "click", function(e){
    $('p', e.delegateTarget).show()
    //This means show all <p> elements in the context defined by e.delegateTarget
})

look at this fiddle http://jsfiddle.net/jWYKv/

like image 200
Nicola Peluchetti Avatar answered Nov 30 '25 10:11

Nicola Peluchetti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!