nodelist

Edge 15 throws error when using 'for … of' on a NodeList

依然范特西╮ 提交于 2021-02-10 04:02:47
问题 When looking at the ECMAScript compatibility table, it says that Edge 15 and Edge 16 support for ... of loops. However, when I run this code: const list = document.querySelectorAll('[data-test]'); console.log(list); for (const item of list) { console.log(item); } <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> It works in Chrome and Firefox, but not in Edge. Instead it says: Object doesn't support property or method 'Symbol

Edge 15 throws error when using 'for … of' on a NodeList

旧巷老猫 提交于 2021-02-10 04:00:38
问题 When looking at the ECMAScript compatibility table, it says that Edge 15 and Edge 16 support for ... of loops. However, when I run this code: const list = document.querySelectorAll('[data-test]'); console.log(list); for (const item of list) { console.log(item); } <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> It works in Chrome and Firefox, but not in Edge. Instead it says: Object doesn't support property or method 'Symbol

Edge 15 throws error when using 'for … of' on a NodeList

你。 提交于 2021-02-10 04:00:29
问题 When looking at the ECMAScript compatibility table, it says that Edge 15 and Edge 16 support for ... of loops. However, when I run this code: const list = document.querySelectorAll('[data-test]'); console.log(list); for (const item of list) { console.log(item); } <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> It works in Chrome and Firefox, but not in Edge. Instead it says: Object doesn't support property or method 'Symbol

Edge 15 throws error when using 'for … of' on a NodeList

与世无争的帅哥 提交于 2021-02-10 03:59:26
问题 When looking at the ECMAScript compatibility table, it says that Edge 15 and Edge 16 support for ... of loops. However, when I run this code: const list = document.querySelectorAll('[data-test]'); console.log(list); for (const item of list) { console.log(item); } <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> <div data-test></div> It works in Chrome and Firefox, but not in Edge. Instead it says: Object doesn't support property or method 'Symbol

Why it is not possible to call forEach on a nodeList?

倾然丶 夕夏残阳落幕 提交于 2021-02-07 12:15:36
问题 I am using a forEach to loop through a nodeList. My code is as follows var array = document.querySelectorAll('items'); array.forEach(function (item) { console.log(item); }); And this code throws an error as Uncaught TypeError: array.forEach is not a function Then after reading few online blog articles i changed the code to this. [].forEach.call(array, (function (item) { console.log(item); })); Could someone please explain why it is not possible to call forEach on a nodeList and what does the

Why it is not possible to call forEach on a nodeList?

醉酒当歌 提交于 2021-02-07 12:13:35
问题 I am using a forEach to loop through a nodeList. My code is as follows var array = document.querySelectorAll('items'); array.forEach(function (item) { console.log(item); }); And this code throws an error as Uncaught TypeError: array.forEach is not a function Then after reading few online blog articles i changed the code to this. [].forEach.call(array, (function (item) { console.log(item); })); Could someone please explain why it is not possible to call forEach on a nodeList and what does the

Why do Array.prototype.slice.call(nodeList) for DOM elements?

前提是你 提交于 2021-02-05 07:34:45
问题 Lots of JavaScript libraries (jQuery, Zepto) seem to be calling Array.prototype.slice.call on querySelectorAll(), getElementsByTag or ClassName results... From reading many many similar questions/answers on StackOverflow I do understand that its to convert a NodeList result to a real Array so that you can invoke Array methods (slice, pop) on the results which are not available on NodeLists - but what I don't understand is why? You don't usually really need slice/pop on a list of DOM nodes +

Find elements in a Node without the proper namespace, in Java

≡放荡痞女 提交于 2021-02-04 16:50:27
问题 So I have a xml doc that I've declared here: DocumentBuilder dBuilder = dbFactory_.newDocumentBuilder(); StringReader reader = new StringReader(s); InputSource inputSource = new InputSource(reader); doc_ = dBuilder.parse(inputSource); Then I have a function where I pass in a string and I want to match that to an element in my xml: void foo(String str) { NodeList nodelist = doc_.getDocumentElement().getElementsByTagName(str); } The problem is when the str comes in it doesn't have any sort of

How is the NodeList implemented?

有些话、适合烂在心里 提交于 2020-07-18 22:25:11
问题 The DOM NodeList (as returned e.g. by element.getElementsByTagName) is an interesting object, in that it is not a snapshot, but reflects changes to the document made after you have created the NodeList. I was wondering how one would implement such a collection: Completely lazy evaluation must be horribly slow, but keeping a cached version consistent requires a lot of book-keeping internally. I tried to google for blog articles on the subject, and also tried to find the relevant source code

How is the NodeList implemented?

余生颓废 提交于 2020-07-18 22:24:58
问题 The DOM NodeList (as returned e.g. by element.getElementsByTagName) is an interesting object, in that it is not a snapshot, but reflects changes to the document made after you have created the NodeList. I was wondering how one would implement such a collection: Completely lazy evaluation must be horribly slow, but keeping a cached version consistent requires a lot of book-keeping internally. I tried to google for blog articles on the subject, and also tried to find the relevant source code