I have this in my HTML
<a class='deleteLink' href='system/id'>link</a>
Then using jQuery, I run this in $(document.ready(function()
alert($('a.deleteLink').attr('href'));
Which shows system/id
But running this:
alert($('a.deleteLink').href);
Shows undefined
If I add an Id to the a tag like this
<a id='myId' class='deleteLink' href='system/id'>link</a>
Then
alert(myId.href);
shows http://localhost/system/id which is what I want to get from jQuery (so I can do something like
$.post($('a.deleteLink').href);
Can anyone help me with getting the full href value out of jQuery (1.2.6) please?
$(‘…’) returns a jQuery object (also called ‘wrapped set’). The wrapped set does not have a href attribute. If you do this:
It should return the href attribute properly. When you deal with ‘myId’, you’re dealing with a DOM element object. Quite different to a wrapped set. The index operator I used there is short for get(0) and that returns an element from the wrapped set.