Problems with jquery selector
Posted
by Gandalf StormCrow
on Stack Overflow
See other posts from Stack Overflow
or by Gandalf StormCrow
Published on 2010-04-25T13:18:32Z
Indexed on
2010/04/25
13:23 UTC
Read the original article
Hit count: 332
jQuery
|JavaScript
I have a trouble with selecting element attributes with jquery here is my HTML:
<a class="myselector" rel="I need this value"></a>
<div class="someClass" id="someID">
...bunch of elements/content
<input type="button" name="myInput" id="inputID" title="myInput Title" />
...bunch of elements/content
</div>
...bunch of elements/content
Here I'm trying to get the rel value of myselector here is how I tried but its not working :
$('#inputID').live('click',function(){
console.log($(this).closest('a.myselector').attr('rel'));
});
Also tried this since all is wrapped in wrapper div :
$('#inputID').live('click',function(){
console.log($(this).parent('div.wrapper').find('a.myselector').attr('rel'));
});
I get undefined
value in firebug in both cases, I use live because div#someID
is loaded in the document its not there when page first loads. Any advice, how can I get my selector rel value?
© Stack Overflow or respective owner