I have an solution:
var addContent = {
...
append: function (obj, data, callBack) {
"use strict";
obj.append(data);
callBack();
}
}
The “addContent.append()” function add its data parameter value to its obj and call its callBack(), it is working as well!
But the “obj parameter” hasn’t been in DOM then those element what found it in “data parameter” not available.
For example:
var to = jQuery('<div>');
addContent.append(to, '<div id="element1"></div>', function () {
alert(jQuery('#element1').length);
});
This code says “0”.
Have you any solution?
Thanks!
If I’ve understood your question correctly, the problem is that the element referred to by
tois not in the DOM, so when you try to select elements that have been appended to it, they are not found (since their parent is not in the DOM).I think what you may be wanting is the context argument:
This will select elements matching
#element1that are descendants ofto.