开发者

Jquery getting id from inserted HTML snippet

I'm inserting a snippet of HTML through .get, and the new HTML when inserted (using .append) will have an <li> element with an id attribute I need. Any way of getting a reference to the last inserted element, 开发者_JS百科and query from there, perhaps? Any good ideas?


$(yourhtml).find('li:last').attr('id');


You can also use the :nth-child selector.

$("li:nth-child(3)").attr('id'); //selects the third, as an example

http://api.jquery.com/nth-child-selector/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜