user405398
user405398

Reputation:

How to find and remove attributes in cloned item using jQuery?

I trying to clone a div content with below code.

var clonedItem = $("#cloneableSchoolTab").clone();
clonedItem.find(".clonableSchool").addClass("clonedSchoolTab" + schoolTabCount );
$("#clonedSchoolTabsContainer").append(clonedItem);

First line gets the whole target item. But, the excecution of second line, the value of clonedItem changed as empty array. I dont know. If i merge the first 2 line, the reasult was same as the above code.

HTML Code:

<div id="cloneableSchoolTab" class="schoolInput">
<input type="text" id="schName"/>
<input type="text" id="schDes"/>
</div>

Any help would be appreciative.

Thanks in advance

Upvotes: 0

Views: 794

Answers (1)

Arnab
Arnab

Reputation: 726

Can you post some HTML code, so that we can see what are the elements the above code is trying to clone, the only thing that I can see is if the find() method fails to find an element with class name ".clonableSchool" then it is constructing an empty jQuery object, as the jQuery doc says:

the .find() method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements

Note: I believe it should be a comment not an answer, but I don't have that privilege yet, sorry.

Upvotes: 1

Related Questions