dom

Ist there a way to check if two DOM elements are equal?

Hi, It's no problem to find an element by position and the position of an element in Javascript. But is there are general way to compare them? The only way I could think of is comparing ids or classnames, but not all elements have ids or classnames. ...

JavaScript DOM : add an attribute to a <tr>

I want to create a JavaScript function that parses my HTML page, get the Table by it's ID, and after that, add a class attribute to each <tr> as if the line is the 1st, I'll add : class="line1" to the <tr> but if the line is the second, I'll add class="line2" to the <tr> How to do please ...

How to parse HTML with PHP?

Suggestion for a reference question. Stack Overflow has dozens of "How to parse HTML" questions coming in every day. However, it is very difficult to close as a duplicate because most questions deal with the specific scenario presented by the asker. This question is an attempt to build a generic "reference question" that covers all a...

Template performance: static files vs hardcoded DOM.

Hi there! This question might be theoretical but i think some of the cases it makes sense. I am just wondering about which solution is the most efficient: loading HTML templates or build up them with DOM functions? Both has pros/cons and there's a lot of other factors that can close off any of them: For example it's obvious that DOM-co...

How to read large XML file consisting of large number of small items efficiently in Java?

I have a large XML file that consists of relatively fixed size items i.e. <rootElem> <item>...</item> <item>...</item> <item>...</item> <rootElem> The item elements are relatively shallow and typically rather small ( <100 KB), but there may be a lot of them (hundreds of thousands). The items are completely independent of each o...

How do I retrieve all text in an HTML DOM but exclude SCRIPT and STYLE tags?

I know how to quickly extract text nodes from a DOM: document.evaluate('//text()', document, null, XPathResult.ANY_TYPE, null) But is there an easy way to exclude text from SCRIPT, STYLE, or other tags that are not shown to the user? Something like: '//text()[ parent.name not in ("SCRIPT", "STYLE") ]' Thanks, Mike ...

Open a new browser window/iframe and create new document from HTML in TEXTAREA?

I'm trying to write a web application using the new offline capabilities of HTML5. In this application, I'd like to be able to edit some HTML—a full document, not a fragment—in a <textarea>, press a button and then populate a new browser window (or <iframe>, haven't decided yet) with the HTML found in the <textarea>. The new content is n...

PrettyPrinting. Ignoring whitespaces.

Hi 1st Question, be gentle. I'm trying to use javax.xml.transform.Transformer to format some xml string to be indented / spaceless between the tags. If there are no spaces between the tags, it works ok. If there are it acts weird. I'll post an example. I tried to follow up on the following topic : http://forums.sun.com/thread.jspa?mess...

In PHP, why do I have to execute the removeChild method twice on a DOMNode from which I have just removed the style-attribute?

I have a script in PHP which removes empty paragraphs from an HTML file. The empty paragraphs are those <p></p> elements without textContent. HTML File with Empty Paragraphs: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- This page is used with remove_empty_paragraphs.php script. This page contains empty parag...

Moving a node from one XML document to another using SimpleXML

I realize that my request is not possible using just SimpleXML -- that much I did figure out. Here is what I tried: $newXML = simplexml_load_file($filePath); $domNewXML = dom_import_simplexml($newXML); $domItem = dom_import_simplexml($items[$itemQty]); <-- item I want to move $domNewItem = $domItem->cloneNode(true); $newNode = $domNew...

How to correctly use innerHTML to create an element (with possible children) from a html string?

Note: I do NOT want to use any framework. The goal is just to create a function that will return an element based on an HTML string. Assume a simple HTML Document like such: <html> <head></head> <body> </body> </html> All functions mentioned are in included the head section and all DOM creation/manipulation is done at the end of ...

Is there a tool to help me understand DOM traversal in jQuery?

Hello, I think I have a basic understanding of DOM traversal, but I doubt I'm doing it efficiently. For example: <textarea name="description"></textarea> <p class="notes"><small>100 characters or less <span class="remainder"></span></small></p> I have a keyup event listener on the textarea. I want the .remainder span to display so...

Force XML character entities into XmlDocument

I have some XML that looks like this: <abc x="{"></abc> I want to force XmlDocument to use the XML character entities of the brackets, ie: <abc x="&#123;"></abc> MSDN says this: In order to assign an attribute value that contains entity references, the user must create an XmlAttribute node plus any XmlText and XmlEntit...

document.readystate of "interactive" vs. ondomcontentloaded?

Could anyone tell me the difference between the "interactive" state of document.readyState and "DOMContentLoaded"? I couldn't find a lot of info on the "interactive" state and what specifically is available to be used in the page. This page says: interactive - Has loaded enough and the user can interact with it Which seems a hel...

How can i load a javascript file using a bookmarklet that in turn does not redirect/rewrite the page?

I'm trying to load this remote debugging solution to debug/interact with DOM/js live. The instructions ask you to put a script block and script link into the HEAD of the page to get it all working. That's fine. It's a great tool. But what if i wanted a bookmarklet-like way of just "inserting" it into any page. I don't see why this can't...

Javascript jQuery best way to insert a big piece of code into DOM

I have a big piece of code that needs to be inserted into DOM at some point. The code also contain some variables: <ul id="info'+value+'" class="info"><li class="hide"></li><li class="lock"><ul> // just a piece of the code with variable "value" Right now I am doing: var codeToInsert = "<some code/>" codeToInsert.insertAfter('#someID'...

How do I change the Javascript src file on client side?

Within my body tag, I have this: <script src="http://maps.google.com/maps?file=api&amp;amp;v=2.x&amp;amp;key=ABQIAAkh87y8Hjhg76ty" type="text/javascript"></script> Is it possible to add Javascript or jQuery in the head of the page to change the "key" parameter in the script source. I am trying to do this before the render reaches the ...

Is there an easy way to clear an SVG element's contents?

In HTML, it's very convenient to be able to say: div.innerHTML = ""; In order to clear a <div> element. Is there any equivalent if I have an <svg> element instead? There seems to be neither innerHTML nor innerXML or even innerSVG. I know the SVG DOM is a superset of the XML DOM, so I know I can do something like this: while (svg.la...

How to check if the element is not the first-child?

How do you know if the current element is not the first-child? It should work with $(this), for example: $("li").click(function(e) { if (/* $(this) is not the first-child */) { /* do something */ } }); ...

DOM traversal one by one node using jquery

Hi I wanted to traverse node by node on a web page by maintaining sequence. e.g. Below is basic DOM : <BODY> <DIV id ='1'> Test 1 </DIV> <DIV id='2'> Details about <SPAN id='3'> Execution </SPAN> </DIV> </BODY> As per above example I want traverse each node by node i.e. 1st Traversal : <BODY> 2nd Traversal : <DIV id =...