> I am fairly new to jQuery so excuse me if this is a somewhat dumb > question. I have a click function applied to all my links with the > class "delete". How do I select the parent div of this link? I have > tried the code below with no success. Thank you. > > <div class = 'grey'> > <a href = '#' class = 'delete'>Hide my parent div</a> > </div> > > <script> > > $(".delete").click(function() { > > $(this + ":parent").toggle("slow"); > > }); > > </script>
If you know the immediate parent is the node you want you can just use the "parent" method: var parent = $(this).parent(); Depending on the markup sometimes you need to be more specific: var greyDiv = $(this).parents('div.grey:first'); Mike