3

I have the following html

<div id="list_item_template"><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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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

is not advisable... read this...

use .click() instead...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.