dom

Is there a cross-browser solution for getSelection()?

I need to make a comment mechanism in which user highlights a piece of text, clicks "comment this", and then does something. The Javascript code has to know not only the selected text (this is trivial), but also the anchorOffset, to know exactly from which to which character the text was selected. I've found a cross-browser solution tha...

Xml Dom library with unit tests

Googled for a Xml Dom open source library that ships with unit tests, but could not find any. Are there any dom libraries, java or .net that have unit tests? ...

link element onload

Is there anyway to listen to the onload event for a <link> element? F.ex: var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'styles.css'; link.onload = link.onreadystatechange = function(e) { console.log(e); }; This works for <script> elements, but not <link>. Is there another way? I just need to kn...

Identify link on contextmenu event in safari extension

Hi! I'm trying to build a safari extenstion (mostly for learning purposes) that creates a delicious bookmark, when the user right clicks on a link. I've watched the WWDC Creating a Safari Extension video and everything is working fine. Except that i don't have a clue how to find out if the user clicked on a link (or just some text) an...

How can I adding/delete a table row using JavaScript?

I'm looking for a simple, effective technique for adding or deleting a row in a html table using JavaScript. (Without using jQuery) ...

How to force DOM modifications done in success function persist within a jQuery.Ajax() call?

Hi, I am getting a JSON object from a webMethod by the call below and I set some textBox values based on the returned objects attributes. Problem is, just for a moment my textBoxes are populated but then immidiately they return back to empty. Do I make a mistake or I cannot make DOM elements modifications within a success function? T...

Attempting to access DOM nodes, getting wrong nodeValues and lengths.

I have the following HTML : <ul id="nav"> <li><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li><a href="#">Four</a></li> </ul> On attempting to walk the element, 1 nav.childNodes.length is 9, What are the nine nodes? 2 nav.childNodes[0].nodeType is 3, but .nodeValue is empty. ...

How do I trigger a function with whatever table row I just dropped in jQuery UI Sortable?

I am working with jQuery UI Sortable plugin, and applying it to a table. How would I trigger a function when dropping whatever element I am dragging? Something similar to below: alert($(this).attr('id')); Full Solution For this, you have to set the container id's to something_number (something_1, something_2, etc). $(function(){ ...

DOM methods and browser compatibility sites

Is there a site anywhere that documents all standard JavaScript DOM methods, events and properties and when they were introduced into the various browsers? I've used W3Schools' XML DOM Object Reference, but it's badly dated, it only tracks IE, Firefox, Opera and W3C, it's missing heaps of newer 'standard' methods, plus I'm certain I ran ...

PHP DOM: change doctype of existing DOMDocument

When creating a DOMDocument with DOMImplementation::createDocument(), you can specify a doctype as the third argument in the constructor. This doctype then gets "tied" to the document and you can retrieve it later with $document->doctype. However, this is a read-only attribute (unlike encoding and version!). Is there any way to change...

Copy DOMNodes from one DOMDocument to another

Hi everybody, I've been trying to combine two XML documents like this: $def = new DOMDocument( '1.0' ); $rdef = new DOMDocument( '1.0' ); $def->load( $path ); $rdef->loadXML( $info ); $r = $def->getElementsByTagName( 'repository' )->item( 0 ); $s = $rdef->getElementsByTagName( 'repository' )->item( 0 ); try { $r->appendChild( $s );...

How to create new node with JTidy

Hi, I am trying to add a meta tag to head section of an html file using JTidy. Problem is I couldn't figure out a way of creating a new node and setting it's attributes. Thanks. ...

Check if LI has "parent" LI using jQuery?

I'm working on the comments section of a WP theme, and the styling requires the use of some clever jQuery in order to make it work right... However, when trying to style admin comments in a long nested UL, I'm having trouble traversing the DOM with jQuery to find the elements I need to adjust the CSS for... Here's what I've tried using:...

Is it bad practice to add properties to DOM nodes?

JavaScript lets you add arbitrary properties and methods to any object, including DOM nodes. Assuming the property was well namespaced (something like _myLib_propertyName) so that it would be unlikely to create a conflict, are there any good reasons not to stash data in DOM nodes? Are there any good use cases for doing so? I imagine do...

[SOLVED] getElementsByTagName object required? Really stuck!

Trying to do a basic XML retrieval. The code works as expected in Firefox and Opera, meaning it alerts with the text value of the "title" node from the XML document. But in IE7, I am getting "object required" from this line. x=xhttp.responseXML.getElementsByTagName("title")[0].childNodes[0].nodeValue; alert(x); Btw, it was wor...

Is there guaranteed ordering on getElementsByName()?

Are the values returned by Javascript's getElementsByName(...) guaranteed to be in the same order that they appear in the DOM? ...

InnerHTML/outerHTML in IE doesn't reflect checkbox state except in quirks mode

I am currently battling an IE JavaScript/DOM bug (what fun) and it has truly stumped me. The code in question copies some checkboxes into a form and needs to maintain their checked state. Problem is, IE (specifically IE8, though I'm guessing others as well) doesn't want to do that. I've narrowed down the bug itself to a very small tes...

Is looping events in JavaScript using document.dispatchEvent possible?

I'd like to create an event loop mechanism in JavaScript/DOM using only dispatchEvent calls. For example: document.addEventListener("LoopingEvent", loop, true); var loop = function() { doSomeWork(); updateUI(); document.dispatchEvent(loopEvent); }; var loopEvent = document.createEvent('Events'); loopEvent.initEvent("Loopin...

When should $(document).ready be used?

I've noticed that $(document).ready(..) causes a noticable delay in applying javascript effects. However I also understand that just having the effect in a <script> can not always work because the DOM may not be ready. When should you always put your code in $(document).ready and when is it ok to bring it out into a global <script> tag...

Converting HTML string into DOM elements?

Hi, Is there a way to convert HTML like: <div> <a href="#"></a> <span></span> </div> or any other HTML string into DOM element? (So that I could use appendChild()). I know that I can do .innerHTML and .innerText, but that is not what I want -- I literally want to be capable of converting a dynamic HTML string into a DOM element so th...