In JavaScript if I append a child which has an ID to another place then it’s removed from original location where they currently are.
In javascript I have an event where I can get selector by using this inside the function
$('.').event(function(){
this
});
This is passed to another function and they work fine. Now I want to pass the clone instead of the object; and remember that this does not have ID.
The old code works by passing this to function as DoSomething(this)
if I make a clone using jQuery clone then I have the jQuery object. So how do I get a reference to this instead of the jQuery object when working with the clone?
var clone = $(this).clone() // this is jQuery object.
//how do I get this out of clone?
Yes, but the same is true of a child node that doesn’t have an
idattribute as well. Anidis only an easy way for you to get a reference to the Element node object; it makes no difference to DOM insertion of cloning behaviour.No,
thisin an event handler gives you the DOM Element node object, not a selector string. A Node can be turned into a jQuery wrapper around it using$(node)and a selector can be turned into a jQuery wrapper on the list of matching nodes using$(selector)but other than this overloading in the jQuery API they’re completely different animals.To pull a Node back out of a jQuery wrapper you can use the
get()method or simple array-like access:to taste. (
get()has some extra features which you don’t need here.)To get the selector used to create a jQuery wrapper you can use the
selectorproperty, but this won’t return anything if the wrapper was created from a node object ($(this)) rather than a selector.