开发者

How do i create and search html in jquery with GM_xmlhttpRequest?

How do i convert html text into a jquery object so i can do .find() and such?

I am grabbing a page with GM_xmlhttpRequest. I have the html of the page. Now with jquery i want to search a link. It had an id so its fairly easy however i have no idea how to make the html into a jquery object.

As a test i wrote alert($('body').html()); which worked. However alert($(thehtml).html()); gets me blank and IIRC i seen a fe开发者_如何转开发w examples with hardcoded html inside of $('') but i could be remembering wrong.


You do not have to call the html method. You can just pass an html string to the jQuery constructor, and it'll automatically create a jQuery object for you.

var someHTML = '<div><p>I am text inside of a "p" inside of a "div"</p></div>';

$(someHTML).find('p');

So, if you have your html string in a variable called thehtml and you want to find all the links in it, all you have to do is $(thehtml).find('a').

Or, if you have an ID on that link, just do $(thehtml).find('#theid').

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜