dom4

Create Xpath Manually

▼魔方 西西 提交于 2020-01-07 02:11:51
问题 I want to create xpath which must contain word "Asia" //div[@id='destination-loadLevel0']/div/ul/li/div/div/span *for Asia //div[@id='destination-loadLevel0']/div/ul/li[2]/div/div/span *for Europe //div[@id='destination-loadLevel0']/div/ul/li[3]/div/div/span *for USA //<div class="col-md-3 level-column column-viewport" id="destination-loadLevel0"> <div class="row"> <ul> <li class="col-md-3 col-hotspot unselectable-text" data-parent-group-id="" data-groupid="2244604" data-name="Asia;|03|00|00|

When to use NodeIterator

不羁岁月 提交于 2020-01-01 02:40:18
问题 Benchmark compares QSA & .forEach vs a NodeIterator toArray(document.querySelectorAll("div > a.klass")).forEach(function (node) { // do something with node }); var filter = { acceptNode: function (node) { var condition = node.parentNode.tagName === "DIV" && node.classList.contains("klass") && node.tagName === "A"; return condition ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT } } // FIREFOX Y U SUCK var iter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, filter,

cross browser compare document position

核能气质少年 提交于 2019-12-07 03:13:01
问题 DOM4 compareDocumentPosition I want to implement compareDocumentPosition. Resig has made a great start at doing just this. I've taken his code and neatened it up function compareDocumentPosition(other) { var ret = 0; if (this.contains) { if (this !== other && this.contains(other)) { ret += 16; } if (this !== other && other.contains(this)) { ret += 8; } if (this.sourceIndex >= 0 && other.sourceIndex >= 0) { if (this.sourceIndex < other.sourceIndex) { ret += 4; } if (this.sourceIndex > other

cross browser compare document position

若如初见. 提交于 2019-12-05 08:07:06
DOM4 compareDocumentPosition I want to implement compareDocumentPosition. Resig has made a great start at doing just this . I've taken his code and neatened it up function compareDocumentPosition(other) { var ret = 0; if (this.contains) { if (this !== other && this.contains(other)) { ret += 16; } if (this !== other && other.contains(this)) { ret += 8; } if (this.sourceIndex >= 0 && other.sourceIndex >= 0) { if (this.sourceIndex < other.sourceIndex) { ret += 4; } if (this.sourceIndex > other.sourceIndex) { ret += 2; } } else { ret += 1; } } return ret; } This works for Element but does not for

When to use NodeIterator

隐身守侯 提交于 2019-12-03 07:45:42
Benchmark compares QSA & .forEach vs a NodeIterator toArray(document.querySelectorAll("div > a.klass")).forEach(function (node) { // do something with node }); var filter = { acceptNode: function (node) { var condition = node.parentNode.tagName === "DIV" && node.classList.contains("klass") && node.tagName === "A"; return condition ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT } } // FIREFOX Y U SUCK var iter = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, filter, false); var node; while (node = iter.nextNode()) { // do thing with node } Now either NodeIterator 's suck

When are MutationObserver callbacks fired?

淺唱寂寞╮ 提交于 2019-11-28 06:47:19
I know that MutationObservers callbacks may get called sometime after the DOM change. But the question is: What is the timing of these callbacks? Do the callbacks enter the event queue of the browsers? If so, when do they enter the queue? Are the callbacks: called immediately after the DOM mutation take place, called as soon as the function that manipulate DOM finishes, called as soon as the call stack is empty, enqueued immediately after the DOM mutation take place, enqueued as soon as the function that manipulate DOM finishes, or at some other time? For example, if the following piece of

create a HTMLCollection

天大地大妈咪最大 提交于 2019-11-27 09:41:44
I'm trying to shim Element.prototype.children which should return a HTMLCollection There is a window.HTMLCollection However var h = new HTMLCollection(); //TypeErrror: HTMLCollection is not a constructor and var h = Object.create(HTMLCollection.prototype); h[0] = div; h.item(0); // Could not convert JavaScript argument Test Firefox 7 and Chrome Apart from shimming HTMLCollection is there any way to interact with it? Also provide feedback on this github issue if you can suggest a solution Here's how I would do it: function MyHTMLCollection( arr ) { for ( var i = 0; i < arr.length; i += 1 ) {

When are MutationObserver callbacks fired?

与世无争的帅哥 提交于 2019-11-27 01:15:21
问题 I know that MutationObservers callbacks may get called sometime after the DOM change. But the question is: What is the timing of these callbacks? Do the callbacks enter the event queue of the browsers? If so, when do they enter the queue? Are the callbacks: called immediately after the DOM mutation take place, called as soon as the function that manipulate DOM finishes, called as soon as the call stack is empty, enqueued immediately after the DOM mutation take place, enqueued as soon as the

Mutation Observer for creating new elements

爷,独闯天下 提交于 2019-11-27 00:32:26
I am trying to make a function go off when a particular div is created. In the simplest of terms, I have something like this: <a href="" id="foo">Click me!</a> <script> $("#foo").live("click",function(e) { e.preventDefault(); $(this).append($("<div />").html("new div").attr("id","bar")); }); </script> Before, I had mutation events listen for the creation of div#bar - something like this: $("#bar").live("DOMNodeInserted", function(event) { console.log("a new div has been appended to the page"); }); Is there an equivalent using Mutation Observers? I tried attrchange.js featured on Can you have a

create a HTMLCollection

最后都变了- 提交于 2019-11-26 14:48:48
问题 I'm trying to shim Element.prototype.children which should return a HTMLCollection There is a window.HTMLCollection However var h = new HTMLCollection(); //TypeErrror: HTMLCollection is not a constructor and var h = Object.create(HTMLCollection.prototype); h[0] = div; h.item(0); // Could not convert JavaScript argument Test Firefox 7 and Chrome Apart from shimming HTMLCollection is there any way to interact with it? Also provide feedback on this github issue if you can suggest a solution 回答1: