dom

DOM manipulation inside SimpleModal box

I'm having issues trying to append dynamically created html inside a SimpleModal box (OSX style). <div id="osx-modal-content"> <div id="osx-modal-title">Foo Modal</div> <div class="close"><a href="#" class="simplemodal-close">x</a></div> <div id="osx-modal-data"> <a class="dynamic">Click</a> <span class="...

jQuery - How can i dynamically add a list item to an unordered list?

Seems like a simple thing to do (although im still learning the ins and outs of jQuery). Here's my HTML: <div id="fbsignup"> <div class="message messageerror"> <strong>There were errors with your registration:</strong> <ul></ul> </div> </div> Here's my (attempted) jQuery: // Check Required Fields. $('#fb...

How to remove "blank markup" with PHP - i.e. multiple nested elements with no text node.

I've installed CKeditor on a client's site that allows them to enter some text using a WYSIYG editor. It is locked down for the most part, only allowing bold, italic, unordered lists, etc. I also run the user submitted HTML through HTML purifier to make sure they don't get smart and start trying to add tables, for example. It is also a ...

javascript: insert large CSS string in one go, into every DOM element

This is a two part question - first I need to get every element that is a child (or subchild, etc) of a parent element, and then I need to reset it's style. As such, I'm looking to do something like the following: var everything = parent.getEveryElementBelowThisOne(); for (i=0; i<everything.length; i++) everything[i].css = "font: 10...

What is better for DOM manipulation - the DOM API or innerHTML?

I have the following code: tr = document.createElement("tr"); root.appendChild(tr); td = document.createElement("td"); td.appendChild(document.createTextNode("some value")); tr.appendChild(td); Well, this code is same as root.innerHTML = "<tr><td>some value</td></tr>"; The first version is probably a better way to go, because the b...

jQuery SVG copy path to another SVG

How can I copy a path or a group out of an SVG-document loaded to the DOM with http://keith-wood.name/svg.html into a new SVG? I want to show thumbnails of the different elements.. every element got its own id, I tried the add-method but nothing happens. Anyone got an idea? ...

jQuery ~ Adjusting href before following it

I have a link with a series of checkboxes, due to the legacy code, when the user clicks on a checkbox the value of it is appended as a comma deliminated list to the href. The trouble is that now that I'm updating the code, I'm finding that the href is being followed quicker than the href is being adjusted, thus the list is being exclude...

Assigning an ID to multiple "placeholding elements"

I have a JavaScript containing a text-input and some "placeholders". The script uses a function to display the value entered in the text-input in some placeholders. The problem is, that if I have to assign an ID to every single placeholder it will take a lot of time - I think avoiding duplication and repetition is called DRY So my quest...

Why does my button need to be clicked twice for the event handler to work the first time, but thereafter just once?

I want the visitor to be able to expand/collapse some sections, and am using: <input onclick="return toggleDiv('xx')" type="button" class="button" value="click here to expand/collapse"/> and in the I have the function: function toggleDiv(a){ var e=document.getElementById(a); if(!e)return true; if(e.styl...

How can I invoke this onkeydown event with a WebBrowserControl in C#?

<input onkeydown="if(isNumber(event)) { this.value = isNumber(event); ajax_submit(this.form); bump_recruiter(); el('altsubmit').setAttribute('disabled', 'disabled'); return false; }" class="captcha" type="text" id="number" name="number" value=""> That is the html. I tried this within the webBrowser.Navigate method: javascript: ajax_su...

jQuery live handler but for each()?

I know that live() can be used to support event handlers for current AND "added later" DOM elements. I wonder how to do the same thing with each()? Like if I have $('.something_or_other').each() but then another DOM element with class="something_or_other" gets added? How can I set it up to automatically apply the each iteration to this...

How to detect whether UA is capable of displaying content inline

Browsers can display certain media inline, and will provided they are sent with content-disposition: inline. What's the best way to detect whether the browser is capable of doing so with a particular type of media? I am running into the question lately with PDFs and Mac/FF, which seems to refuse to display PDFs inline (actually, in iFra...

How can I delay the loading of CSS background images?

I am animating sprites in a HTML/JavaScript game by showing/hiding/repositioning many divs, each with a CSS background image. I'd like to load some of the images only when they are first needed, rather than loading them all when the page is first loaded. Will setting them all to "display:none" initially and then showing/hiding them wit...

What is the preferred method of retrieving class names with jQuery?

So far, I'm using $(this).attr('class'); But I worry about compatibility because I know some browsers do some weird things with class and id attributes. Seems like a great place for jQuery to implement its own method, but I can't find it in the documentation. Isn't there a bug somewhere that has className and id acting on the same ob...

Return node text (non-recursive)

Hi, I'd like to return a table cell's node value. The method text() however, goes down the whole DOM tree and returns a string of all nested nodes (the table cell may have text and html included). Once I have extracted the node's string, I'd like to modify it and write it back to the node. The modified text consists of text and html. I...

Will inserting the same `<script>` into the DOM twice cause a second request in any browsers?

I've been working on a bit of JavaScript code that, under certain conditions, lazy-loads a couple of different libraries (Clicky Web Analytics and the Sizzle selector engine). This script is downloaded millions of times per day, so performance optimization is a major concern. To date, I've employed a couple of flags like script_loading ...

Problem with javax.xml.transform.Transformer. Empty element not showing properly in editor but in Browser.

I have used javax.xml.transform.Transformer and javax.xml.transform.TransformerFactory and org.w3c.dom.Element and org.w3c.dom.Node to create XML file as per my requirement. Its creating XML successfully. The only problem is : <MYADDRESS NAME="AA00001"> <ATTN1>a</ATTN1> <ADDRESS></ADDRESS> // This is empty ADDRE...

How to select nested dom elements.

Hi, I am looking for a way to collect all <a> tags and load then in an array using Mootool 1.1 or pure javascript. <ul class="menu"> <li> <ul> <li><a href="#">Group One</a> <ul> <li><a href="#">I want</a></li> <li><a href="#">I want too</a></li> </ul> </li> <li><a href="#...

Is it better to use pure DOM methods or string concatenation to generate a very dynamic xml file?

I basically have to query the database to grab all the active properties, then grab content under each property for sections such as accommodations/experiences, and based on that generate basically a site map. I'm wondering if I should go with using purely DOM methods ( would have me doing a hundred or so createElements, inside of loops...

Accessing a DOM node

Using just the DOM API, what are all of the different ways I can access a node? For example, I know I can call document.getElementById("header");. I'd like a complete list of ways to get access to this node. ...