dom

Javascript Detect All Images (Including Asynchronous)

Is there a way in javascript to detect all images in a document, including those that may be loaded asynchronously (and maybe after the DOM is ready)? I'm looking to create a function that can detect if Google Analytics has been loaded by searching through the DOM looking for "__utm.gif". document.images doesn't seem to hold this image...

Javascript getElementById lookups - hash map or recursive tree traversal?

Does the DOM have a hash-table of elements whose keys are the elements' ids? I want to know if document.getElementById looks up a hash table or traverses the entire tree. Is this behavior different across browsers? ...

JavaScript getting complete code of element when mouseover or onclick

How can I get the complete HTML code of the element I'm mouseovering or clicking? Using document.onmouseover = function(e){ can I get the full underlying HTML code of the element which triggered the event? Right now, I am able to get the tag name or id or whatever. What I would like is the whole code. For example; if I'm mouseovering a...

How can I programmatically copy all of the style attributes from one DOM element to another

I have a page with two frames, and I need to (via javascript) copy an element and all of its nested elements (it's a ul/li tree) and most importantly it's style from one frame to the other. I get all the content via assigning innerhtml, and I am able to position the new element in the second frame with dest.style.left and dest.style.top...

Undo implementation - DOM manipulations

Is there a library that can be used for implementing undo/redo functionality for DOM element manipulations in JavaScript? I'm writing an prototype.js app (memonaut) that moves around DOM elements, enables editing and deletion of those elements. There are event-handlers and other objects associated with each element operated upon. Not...

Jquery Dom and functions in html body

I have <script>...</script> before my closing body tag here i have the usual $(function() { function test(){ alert("test"); } }); in my html i have input tags <input type="text" onchange="test()" /> I get an error of that test is undefined. I am trying to make IE7 call function onchange I had a whole solution working but ...

jQuery, checking to see if video has height/width

I have a <video> element that is generated by js, and I need to get the height and width of it. var v = $('video'); v.height() returns null, because when it's run, the video hasn't yet been loaded, so no dimensions in the DOM. How do I check to see if the video has received a dimension, and if it hasn't, wait till it has to get the hei...

How can I get reason of page unloading in javascript's onunload event, in IE?

There may be different reasons of page unloading: 1 User closes the current window. 2 User navigates to another location. 3 Clicks the Back, Forward, Refresh, or Home button. 4 User submits a form, and then browser starts to unload current page and load page with results of form submitting. (Assuming that the current window is the fo...

jQuery .next() and .prev() not working as they should!

I want to get the .next() and .prev() sibling of an HTML element without excluding TextNodes. I basically need to understand if an element is directly sorrounded by <br> HTML elements. This would return true: <br> <div></div> <br> This would return false: <br> Some text <div></div> <br> BUT this needs to also return true: <br> ...

The best way to do :not in jQuery?

Hi, I have a menu in jQuery when you click on a link it opens up, but I want it so when you click somewhere else, anywhere else that is not the menu, it becomes hidden. At the moment I'm binding a click event to $(':not(#the_menu)') But this seems like I'm binding a click event to the entire minus the menu, is there a more efficie...

Why is window not identical to window.self in Internet Explorer?

There's a convoluted backstory involving how I came across this, but why is the self property not exactly equal to the window itself? In Safari and Firefox and friends, the results are as I'd expect: > window == window.self true > window === window.self true The same isn't true in Internet Explorer, though: >> window == window.s...

What is the difference between javascript and DOM?

What is the difference between JavaScript and DOM? id DOM related to firefox? is DOM just a source order of HTML elements? ...

where is the best place to place a javascript snippet to alter the DOM of a page before it renders

I have a few dynamic pages and I want to alter certain elements before the page has fully rendered. My snippet is something like document.body.getElementById("change").innerHTML = "<img src..."; I do not have access to change the content server side. Where is the best place to put the snippet to have the code run before the page it ...

If you delete a DOM element, do any events that started with that element continue to bubble?

What behavior should I expect if I delete a DOM element that was used to start an event bubble, or whose child started the event bubble - will it continue to bubble if the element is removed? For example - lets say you have a table, and want to detect click events on the table cells. Another piece of JS has executed an AJAX request tha...

why libxml2 quotes starting double slash in CDATA with javascript

This is my code: <?php $data = <<<EOL <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <html> <script type="text/javascript"> //<![CDATA[ var a = 123; // JS code //]]> </script> </html> EOL; $dom = new DOMDocument(); $dom-...

How to convert a DOM node list to an array in Javascript?

I have a Javascript function that accepts a list of HTML nodes, but it expects a Javascript array (it runs some Array methods on that) and I want to feed it the output of Document.getElementsByTagName that returns a DOM node list. Initially I thought of using something simple like: Array.prototype.slice.call(list,0) And that works fi...

Updating table row by given id with jQuery

Hello all! I need to update a specific table row (via tr id="unique_key") after a successful AJAX call. HTML fragment: <a name=\"p{$product_id}\" class=\"tr{$product_id}\"></a> <tr id="p{product_id}" class="item-row"> <td><h3>{product_id}</h3><a rel="facebox" href="ajax_url">{product_name}</a></td> <td>{image_information}</td> <td>{im...

Adding images to the html with javascript

I've tried some HTML DOM code from several sites, but it isn't working. It isn't adding anything. Does anyone have a working example on this? this.img = document.createElement("img"); this.img.src = "img/eqp/"+this.apparel+"/"+this.facing+"_idle.png"; src = getElementById("gamediv"); src.appendChild(this.img) But it isn't adding anyt...

Collect DOM elements from external HTML documents

I am trying to write a report-generator to collect user-comments from a list of external HTML files. User-comments are wrapped in < span> elements. Can this be done using JavaScript? Here's my attempt: function generateCommentReport() { var files = document.querySelectorAll('td a'); //Files to scan are links in an HTML table v...

i see some symbols in my page, when refresh it

when i refresh my page, one moment it shows  symbols, only after it the normal page! i've set charset=UTF-8 in my page could you help me? thanks UPDATE: here is the link to my page ...