JavaScript NodeList

Seems like you can use the same that makes the args array-like object become an array. (See here) var inputs = document.getElementsByTagName(‘input’); var selects = document.getElementsByTagName(‘select’); inputs =; selects =; var res = inputs.concat(selects); alert(res.length);

Is it possible to get reference to comment element/block by JavaScript?

var findComments = function(el) { var arr = []; for(var i = 0; i < el.childNodes.length; i++) { var node = el.childNodes[i]; if(node.nodeType === 8) { arr.push(node); } else { arr.push.apply(arr, findComments(node)); } } return arr; }; var commentNodes = findComments(document); // whatever you were going to do with the comment… console.log(commentNodes[0].nodeValue);

Dynamic creation of table with DOM

You must create td and text nodes within loop. Your code creates only 2 td, so only 2 are visible. Example: var table = document.createElement(‘table’); for (var i = 1; i < 4; i++){ var tr = document.createElement(‘tr’); var td1 = document.createElement(‘td’); var td2 = document.createElement(‘td’); var text1 = document.createTextNode(‘Text1’); var text2 = document.createTextNode(‘Text2’); td1.appendChild(text1); … Read more

The package org.w3c.dom is accessible from more than one module: , java.xml

I had a similar issue because of a transitive xml-apis dependency. I resolved it using a Maven exclusion: <dependency> <groupId>org.apache.xmlgraphics</groupId> <artifactId>fop</artifactId> <version>0.95</version> <exclusions> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> </dependency> Another dependency that just causes trouble and I don’t have a solution other than removing it is this one: <dependency> <groupId></groupId> <artifactId>xmlparserv2</artifactId> <version>${oracle.version}</version> </dependency> Use mvn … Read more

Add elements to the DOM given plain text HTML using only pure JavaScript (no jQuery)

Try assigning to the innerHTML property of an anonymous element and appending each of its children. function appendHtml(el, str) { var div = document.createElement(‘div’); div.innerHTML = str; while (div.children.length > 0) { el.appendChild(div.children[0]); } } var html=”<h1 id=”title”>Some Title</h1><span style=”display:inline-block; width=100px;”>Some arbitrary text</span>”; appendHtml(document.body, html); // “body” has two more children – h1 and span.