开发者

Simple jQuery selector

开发者 https://www.devze.com 2023-03-09 21:52 出处:网络
I am trying to select the surroundelement when a开发者_开发技巧 image within the span is clicked \'remove()\', but I am a little new to jQuery and can\'t figure out how to do it. I can\'t use a unique

I am trying to select the surround element when a开发者_开发技巧 image within the span is clicked 'remove()', but I am a little new to jQuery and can't figure out how to do it. I can't use a unique id as the element are generated dynamically.

For example:

<span class='type_link'> <img src='/images/deleteCross.gif' onclick='remove()' />Example</span>

I want to select the span when the image is clicked.


Here is an example to hide the parent element of the image:

<span class='type_link'> <img src='/images/deleteCross.gif' onclick='$(this).parent().hide();' />Example</span>

The trick is to use "this" and the parent()-function.

Cheers, Chris


Look at this (for selector) and this (for event)!

Also W3schools provide Good example for first step in Jquery.


How about .parent() http://api.jquery.com/parent/

0

精彩评论

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