need help with jquery selector
Posted
by Gandalf StormCrow
on Stack Overflow
See other posts from Stack Overflow
or by Gandalf StormCrow
Published on 2010-03-14T14:55:50Z
Indexed on
2010/03/14
15:05 UTC
Read the original article
Hit count: 173
jQuery
|JavaScript
I have a following HTML :
<ul class="someclass">
<li id="1">
<button type="button" class="grey"></button>
</li>
<li id="2">
<button type="button" class="grey"></button>
</li>
<li id="44">
<button type="button" class="grey"></button>
</li>
<li id="54">
<button type="button" class="grey"></button>
</li>
</ul>
Now here is what I'm trying to accomplish with jquery :
When button is clicked to find out id
of parent li
, here is how I tried and failed:
$(".grey").live('click', function(){
alert($(this).parents("li").attr("id"));
alert($(this).parents("li:first").attr("id"));
});
Both give me null
alerted, how can I do this ?
© Stack Overflow or respective owner