开发者

How do you access the DOM node in jquery inside of a javascript variable?

I have the following html

<div id="list_item_temp开发者_运维百科late"><li><a href="#">Text</a></li></div>

and javascript:

var item = $("#list_item_template").clone();

What I want to do is access the inner <a> tag of the cloned copy and add an attribute. Without cloning I would just do:

$("#list_item_template a").attr("onclick", "SomeFunction()");

However, I need to perform that operation on the cloned copy, not on the html currently on the page. How would I do this?


item.find('a'); should do it.


$("#list_item_template a").attr("onclick", "SomeFunction()");

is not advisable... read this...

use .click() instead...

$("a",item).click(SomeFunction);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜