开发者

Jquery select a var?

$.get('example.com',function(data){
link = $(data #someid).attr("href") // how to do this???
})

I load a page from other web (ex: $.get) and pass it to data, now how to use .attr() or Se开发者_StackOverflow社区lectors on the data (sorry for my english problem)


I dont know what is the content of the data, but if it is valid HTML, you could do it as this

$.get('example.com',function(data){
link = $("#test",$(data)).attr("href") // this is how you should do it
});

Imagine data HTML is

<a id="test" href="http://test.com">This is a link</a>

Hope helps :)


You have a few syntax errors:

You need to add a data variable in the callback function:

$.get('example.com', function(data) {

Inside, you can look it up like this:

link = $("#someid", $(data)).attr('href')

Here's all of it:

$.get('example.com', function(data) {
    link = $("#someid", data).attr('href')
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜