I’m using jQuery .get to grab elements from another page; I want to get the “nth” href attribute, which I’m trying to do with the code below. As you can see, I’m trying to change the value of an ID to a specific URL. I think there’s a problem with my use of .find, but couldn’t figure out. Thanks a ton for any help.
JS
$.get('/file.xml', function(data)
{
var $links = $(data).find('a').attr('href'),
selectedlink = $links.eq(selectedValue);
var link = selectedlink.text();
$("#fvlink").val(link);
});
HTML page with URLs
<body>
<li><h2><a href="http://www.whatever1.coy">2060</a></h2><span class="desctext">This is the second slide</span></li>
<li><h2><a href="http://www.whatever2.com">2057</a></h2><span class="desctext">This is the third slide</span></li>
<li><h2><a href="http://www.whatever3.com">2056</a></h2><span class="desctext">This is the fourth slide</span></li>
</body>
Because
$(..).attr()returns a string,$linkswon’t be an jQuery object. You need to drop the call toattr():