dom

Getting closest element by id

I have two elements: <input a> <input b onclick="..."> When b is clicked, I want to access a and manipulate some of its data. A does not have a globally unique name, so document.getElementsByName is out. Looking into the event object, I thought event.target.parentNode would have some function like getElementsByName, but this does not ...

What is the best tool to benchmark my JavaScript?

I'm currently working on a JavaScript tool that, during the course of its execution, will ultimately traverse each node in the DOM. Because this has potential to be a very expensive task, I'd like to benchmark the performance of this script. What's the best, free tool for benchmarking a script such as this across the major browsers? Ide...

jQuery "after" selector question

I can't seem to figure out a good way to do this, but it seems like it should be simple. I have an element that I want to append a div to. Then I have another element that I want to clone and shove into that intermediate div. Here's what I was hoping to do: $("#somediv > ul").after("<div id='xxx'></div>").append($("#someotherdiv").cl...

How do I maintain position of a DragPanelExtender across postbacks?

I already found this article: http://www.dotnetcurry.com/ShowArticle.aspx?ID=181&amp;AspxAutoDetectCookieSupport=1 But I've got a different situation. I am embedding some hiddenFields inside of the master page and trying to store the position of the dragPanel in those. I am using javascript to store the position of the dragPanel and ...

Figure out div that is visible out of four divs.

I need to figure out what div is visible out of four possible divs using jQuery. Only one of those div's will be visible at any given time. This is what I have that works so far: $("#FeatureImage1:visible, #FeatureImage2:visible, #FeatureImage3:visible, #FeatureImage4:visible").attr("id"); Is there a way to refactor this? Is there ...

Code to make a DHTMLEd control replace straight quotes with curly quotes

I've got an old, legacy VB6 application that uses the DHTML editing control as an HTML editor. The Microsoft DHTML editing control, a.k.a. DHTMLEd, is probably nothing more than an IE control using IE's own native editing capability internally. I'd like to modify the app to implement smart quotes like Word. Specifically, " is replaced w...

innerHTML manipulation in JavaScript

I am developing a web page code, which fetches dynamically the content from the server and then places this content to container nodes using something like container.innerHTML = content; Sometimes I have to overwrite some previous content in this node. This works fine, until it happens that previous content occupied more vertical spac...

Getting notified when the page DOM has loaded (but before window.onload)

I know there are some ways to get notified when the page body has loaded (before all the images and 3rd party resources load which fires the window.onload event), but it's different for every browser. Is there a definitive way to do this on all the browsers? So far I know of: DOMContentLoaded : On Mozilla, Opera 9 and newest WebKits....

Order of DOM NodeList returned by getChildNodes()

The DOM method getChildNodes() returns a NodeList of the children of the current Node. Whilst a NodeList is ordered, is the list guaranteed to be in document order? For example, given <a><b/><c/><d/></a> is a.getChildNodes() guaranteed to return a NodeList with b, c and d in that order? The javadoc isn't clear on this. ...

How do I use Javascript to locate by X-Y Coordinates in my browser?

I'm trying to make it so when a user scrolls down a page, click a link, do whatever it is they need to do, and then come back to the pages w/ links, they are at the same (x-y) location in the browser they were before. How do I do that? I'm a DOM Newbie so I don't know too much about how to do this. Target Browsers: IE6/7/8, Firefox ...

How do I get the most recently updated form item to "stick" in Firefox when I copy its container?

I have a dl containing some input boxes that I "clone" with a bit of JavaScript like: var newBox = document.createElement('dl'); var sourceBox = document.getElementById(oldkey); newBox.innerHTML = sourceBox.innerHTML; newBox.id = newkey; document.getElementById('boxes').appendChild(columnBox); In IE, the form in sourceBox ...

Why don't self-closing script tags work?

What is the reason browsers do not correctly recognize: <script src="foobar.js" /> // self-closing script tag Only this is recognized: <script src="foobar.js"></script> Is it breaking concept of XHTML support? Note: This statement is correct at least for all IE(6-8 beta 2). ...

how do I use the node Builder from Scriptacolus to insert html.

for example this code var html = "<p>This text is <a href=#> good</a></p>"; var newNode = Builder.node('div',{className: 'test'},[html]); $('placeholder').update(newNode); casues the p and a tags to be shown, how do I prevent them from being escaped? ...

Problem accessing the content of a div when that content came from an Ajax call

Here's a very simple Prototype example. All it does is, on window load, an ajax call which sticks some html into a div. <html> <head> <script type="text/javascript" src="scriptaculous/lib/prototype.js"></script> <script type="text/javascript"> Event.observe(window, 'load', function(){ new...

How to create a DOM from a User's input in PHP5?

I can't seem to find any decent info about this on the web. Any advice? ...

How do I programatically set the value of an select box element using javascript?

I have the following HTML select element: <select id="leaveCode" name="leaveCode"> <option value="10">Annual Leave</option> <option value="11">Medical Leave</option> <option value="14">Long Service</option> <option value="17">Leave Without Pay</option> </select> Using a javascript function with the leave code number as a param...

Most common cause of "java.lang.NullPointerException" when dealing with XMLs?

My strongest lead is that the code who deals with the incoming XMLs is actually receiving an invalid/incomplete file hence failing the DOM parsing. Any suggestions? ...

Suggestions on how build an HTML Diff tool?

In this post I asked if there were any tools that compare the structure (not actual content) of 2 HTML pages. I ask because I receive HTML templates from our designers, and frequently miss minor formatting changes in my implementation. I then waste a few hours of designer time sifting through my pages to find my mistakes. The thread of...

Javascript and why capital letters sometimes work and sometimes don't.

In notepad++, I was writing a javascript file, and something didn't work: an alert had to be shown when a button was clicked, but it wasn't working. I has used the auto-complete plugin provided with Notepad++, which presented me with "onClick". When I changed the capital C to a small c, it did work. So first of all, when looking at th...

What's a good book to learn Javascript DOM manipulation?

I'm looking for a book I could use to learn the subject of DOM scripting. So far I just have been learning only the things I needed for my given projects online, but I would like to buy a book on the topic so I can fully learn the material as a whole. Any suggestions? ...