dom

Is it ok to manipulate dom before ready state?

This is generally how I manage progressive enhancement whilst keep the experience clean, but how safe is it? is there potential for a race condition and this not working? Imagine the simple abstract scenario, you want to display something differently if you have javascript support.. this is generally what I will end up doing: <div id="...

Use jQuery to check if all div's are hidden

How would I check if all the div's with class test are hidden. And if they are all hidden set wrap1 to hidden. Thanks. <div id='wrap1'> <div class="header">Header 1</div> <div class='test'><a href="#">Test 1</a></div> <div class='test'><a href="#">Test 2</a></div> <div class='test'><a href="#">Test 3</a></div> </div> UPDATE: Thanks ev...

XHTML DOM manipulation with jQuery

I'm using Firefox 3.5. My doctype is XHTML 1.0 Strict. Let's say I want to insert an image into a div with id "foo"; then I might try: var foo = $('#foo'); foo.html('<img src="bar.gif" />'); This does indeed add the image. But I noticed that this was causing some odd behavior later in the document, which I suspected might be due to XH...

Elements positioned relatively don't move when the DOM is updated (IE6 and IE7)

I have a form with a few fieldsets. One fieldset has a table of time preferences set by the user. The user can add and delete time preferences. When they add a row, a table row is dynamically inserted into the DOM using a jQuery append(). The issue is that in IE6 and IE7 any relatively positioned elements on the page do not "bump" do...

Java+DOM: How do I elegantly rename an xmlns:xyz attribute?

Hello! I have something like that as input: <root xmlns="urn:my:main" xmlns:a="urn:my:a" xmlns:b="urn:my:b"> ... </root> And want to have something like that as output: <MY_main:root xmlns:MY_main="urn:my:main" xmlns:MY_a="urn:my:a" xmlns:MY_b="urn:my:b"> ... </MY_main:root> ... or the other way round. How do ...

appendChild in IE6/IE7 does not work with existing elements

I have a div that needs to be moved from one place to another in the DOM. So at the moment I am doing it like so: flex.utils.get('oPopup_About').appendChild(flex.utils.get('oUpdater_About')); But, IE, being, well, IE, it doesn't work. It works all other browsers, just not in IE. I need to do it this way as the element (div) 'oUpdater...

How to obtain the HTML DOM element of a Google Maps marker?

Hey everyone, Given a GMarker JS variable, how do I obtain the HTML DOM element that represents it? I need this so I can insert a <div> of my own into the map with the correct z-index. Thanks. ...

Is there an easier way to reference the source element for an event?

I'm new to the whole JavaScript and jQuery coding but I'm currently doing this is my HTML: <a id="tog_table0" href="javascript:toggle_table('#tog_table0', '#hideable_table0');">show</a> And then I have some slightly ponderous code to tweak the element: function toggle_table(button_id, table_id) { // Find the elements we n...

Automatically making a div appear based on status of radio button with JavaScript

I have a form which posts data to the same page. Based on the user's radio button selection I am inserting checked="checked" into the radio button form element to redisplay the correct selection. This works fine, however when the form is redisplayed (in case of bad input etc), I need a div to be revealed (containing the relevant fields f...

In the DOM are node ids case sensititve?

Is this HTML valid? Or is the id 'a' the same as the id 'A'? <div id="a">alpha</div> <div id="A">Alpha</div> ...

Appending to the dom inside each iteration or create an array and output?

I posted a question yesterday dealing with parsing json data. In one of the follow up answers someone said I was taking a performance hit by using the jQuery append() function within each iteration, while using each(). I was doing: $.getJSON("http://myurl.com/json?callback=?", function(data) { // loop through each post ...

Find DOM element by ID when ID contains square brackets?

I have a DOM element with an ID similar to: something[500] which was built by my Ruby on Rails application. I need to be able to get this element via jQuery so that I can traverse my way up the DOM to delete the parent of it's parent, which has a variable ID that I don't have access to beforehand. Does anyone know how I could go abo...

JAVA element.getElementsByTagName Restrict to Top Level

I have an XML file as follows: <rootNode> <link>http://rootlink/&lt;/link&gt; <image> <link>http://imagelink/&lt;/link&gt; <title>This is the title</title> </image> </rootNode> The XML Java code using DOM is as follows: NodeList rootNodeList = element.getElementsByTagName("link"); This will give me all o...

How does the Javascript print function work? Can I create a document using javascript and print it off?

I know you can use window.print() to print the current page... but what I want to know is can I build a document using javascript in order to populate it with data and print it off? Just like you can have html/xml as a javascript object, can you do something similar to this: var name = "Matt"; var htmlDocumentToPrint = "<html><body><di...

Manipulating an element using jquery not working

I have a regular div, like so: <div id="registry_ViewPanel"> <div id="registry_Header">Register</div> <div id="registry_Content"> //Registry fields here </div> </div> with css: #registry_ViewPanel { width:400px; height:400px; border:1px solid; background-color:#fff; display:none; position:fi...

What DOM manipulation can be done on Text nodes?

I'm going through the DOM using childNodes and I have a reference to a Text node, and I need to modify its "inner HTML" .. but I tried and it does not work or have such a property. Apart from replaceChild(), what functions can I use to manipulate the inner HTML of this Text node? ...

selecting specfic options within a dropdown list with jquery

Hi - I'd like to be able to select a specific option within a dropdown list in order to manipulate it. For example, $("#mylist > option14").replaceWith(<option value="option155">New Option</option> How can I do this? Selecting through the child selector doens't seem to work. Thanks. ...

html <br> and innerHTML problem

i have some content like this var p = i myself Abhimanyu Singh Yadav when i m trying to insert into as innerHTML to some div the whole content appears in one line.i m using <pre> tag to avoid this problem.but need some appropriate solution. ...

(Javascript) Inserting elements dynamically in a specific position

Basically what I have is this: <body> <div class="class1"> </div> <div class="class2"> </div> <div class="class3"> </div> ... </body> I have no idea why the site creator used classes instead of IDs (they're unique), but it doesn't really matter as I'm writing a GM script and so getElementsByClassName('')[0] effectively does the ...

In Greasemonkey/javascript, how can I handle new elements added to page?

I have written a Greasemonkey script which manipulates the contents of certain elements with the following selector: $("span.relativetime").each(function() { $(this).html("TEST"); }); However, sometimes matching elements are added to the page through AJAX, and I don't know how to handle those new elements. I have tried this, but it d...