admin管理员组文章数量:1304878
DOMNodeInserted
event is called when the node "be appended to", or "be appended"?
I ask this because the following code:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (container.addEventListener) {
container.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
and that:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (textNode.addEventListener) {
textNode.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
Both invoke OnNodeInserted
in Chrome. Is it a bug?
DOMNodeInserted
event is called when the node "be appended to", or "be appended"?
I ask this because the following code:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (container.addEventListener) {
container.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
and that:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (textNode.addEventListener) {
textNode.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
Both invoke OnNodeInserted
in Chrome. Is it a bug?
2 Answers
Reset to default 9This is from W3C
DOMNodeInserted Fired when a node has been added as a child of another node. This event is dispatched after the insertion has taken place. The target of this event is the node being inserted. Bubbles: Yes Cancelable: No Context Info: relatedNode holds the parent node
The key is the Bubbles: Yes - thats why its being fired on the container as well.
If you want to prevent the event from bubbling up just use event.stopPropagation(); in your text node callback. Events are then no longer handled up the dom tree.
本文标签: javascriptWhen is quotDOMNodeInsertedquot event calledStack Overflow
版权声明:本文标题:javascript - When is "DOMNodeInserted" event called? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741793110a2397776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论