开发者

Jquery getting id from inserted HTML snippet

开发者 https://www.devze.com 2023-02-28 05:15 出处:网络
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 in

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

精彩评论

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