dom

What are the drawbacks of accessing DOM elements directly by ID?

Today I stumbled upon the possibility to access a DOM element in Javascript simply by its id e.g. like this: elementid.style.backgroundColor = "blue" I tested with a very short snippet if this works in IE, Firefox and Chrome - and it does. Here is the snippet I used: <html><head> <script> function highlight() { content.st...

Using chrome for web development - how to dock the inspector?

I know Firebug is the standard, but I find myself using Chrome a lot (screen space, speed, etc.) Anyway, I think their inspector is pretty good, too. Certainly good enough that I don't want to fire up FF and navigate thru a site every time that I want to take a peak at the DOM. However, probably the most annoying part is that I can't do...

How can I identify if a webpage is an HTML one or of a different mimetype (.mp3,.jpeg) via the DOM across all browsers?

I want to determine the mimetype of a webpage. I am specifically looking for a statement like this, which works for Firefox: if (document.contentType == 'text/html') { performX(); } else { performY(); } However, a statement which works across all browsers is preferred. Some google result suggested me this, but it fail...

Access Iframe with Javascript on external domain

Hi. I'm looking for a way to access read-only properties of a page on a IFRAME. Specifically I would like to read the selection. Apparently I can't read it because the document lies on another domain. Is there a way to read them? ...

How to turn a very long column into multiple shorter ones?

This is a challenge question / problem. Hope you find it interesing. Scenario: You have a very long list (unreasonably long) in a single column. It would be much better displayed in multiple shorter columns. Using jQuery or another tool, what do you do? The format of the list is as follows: <div class="toc"> <dl> <dt>item 1</dt> ...

How does global Javascript object save state?

/************************************************************************** * * Function: toggleVis * * Description: Following Function hides and expands the main column. * * ***************************************************************************/ // Set the default "show" mode to that specified by W3C DOM // c...

Javascript If Statement for Text between two Tags

Hello: I am trying to write a javascript function with an "if" statement that will execute a command if the text between two tags match. I have been able to write many "if" statements in which a command is executed when the value within an input textbox equals that of the "if" statement criteria such as: function Test() { if (docu...

Dom book which introduces DOM as much as possible?

I want to read a book that systematically introduces dom with live examples. Any recommendation? ...

changing class of a <span> element with JavaScript

I am trying to change the class of a element with Javascript using the below code: parent.document.getElementById('<?php echo $markid ?>').class = 'unlistened'; Not having much luck though. How do I do this properly? ...

How to access mxml (Flex) DOM elements?

Is there a way to access the DOM-Elements of a mxml file in a way that you can in JS (e.g. using Prototype or jQuery)? I need to know if a top-level element has a child (sub-sub-...-childs) with a certain id. In JS (using prototype) it would be something like: $('tabs').select('[id="something"]'); Any ideas? ...

Remaning checkbox name from JS cause IE to run slow, not FF?

I have a list of check boxes. For the check boxes that are selected, I change it's name before submitting. In FF the function works. In IE I get: A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script? YES/NO Not sur...

How to do basic DOM manipulation (clear content, append to content) with YUI?

I am doing a project with YUI where I attempt to do things I have previously been doing with jQuery. I am finding it difficult to do some basic operations, and namely: clear content of DOM element append to content of DOM element In jQuery, I would do: $(".someSelector").empty().append("<div>something</div>"); How to do the above ...

How can I get an element by name with jquery?

I have a table column I am trying to expand and hide. jQuery seems to hide the column when I select it by class but not by element name. Why does $(".bold").hide(); <--This work $("tcol1").hide(); <--This NOT work?? The second column has the same name and id for all rows:. <tr> <td>data1</td> <td name="tcol1" id="tco...

JS/Flash - Drag anchor containing img vs Drag img w/out anchor - How to get the img inside the anchor?

Cryptic title, but it's hard to explain. With Firefox, head over to http://images.google.com do a random search, and then drag the first search result to the URL bar. You'll see it it goes to the page that had the image anchor. Then click the "see full size image" link, and then drag the image to the address bar. In the first example...

can a textNode have a childNode which is an elementNode ?

Say,is the following possible: textNode.appendChild(elementNode); elementNode refers to those with nodeType=1 textNode refers to those with nodeType=2 It's not easy to produce. The reason I ask this is that I find a function that adds a cite link to the end of a quotation: function displayCitations() { var quotes = document.getE...

jQuery select elements on 1st "level"

I want to select only the elements on the first "level". Ex: <div id="BaseElement"> <p>My paragraph 0</p> <div> <span>My Span 0</span> <span>My Span 1</span> </div> <span>MySpan 2</span> <span>MySpan 3</span> <p>My paragraph 1</p> </div> Let's say that you got the BaseElement node. var Element = $("div#BaseElemen...

jQuery question: Does using .remove() also properly remove children?

Not that it matters strictly, and maybe I just don't yet fully understand how the DOM works by asking this, but I'm just trying to anticipate if there is some kind of memory leak potential here. If I remove an element that has children, event listeners, etc., do those get cleaned up as well? Or would I be wise to implement some kind of...

MSXML DOM: Add namespace declaration to an existing node in a tree

Problem description: Read an xml file, traverse to a particular node (element), if it does not have a particular namespace declaration, add the required namespace declaration, and write out the file. I need to do this in C++ using Microsoft's MSXML DOM APIs. The namespaceURI property on IXMLDOMNode COM object is read-only according to t...

Hiding a div with specific text as content

Hello. I've got a DIV I want to hide, but I cannot give it a specific ID... actually I cannot change the text of the DIV, since it is retrieved from a database, but I can add some html before it AND I know the exact text content of the DIV. It's something like: <div class="this_div">content_of_this_div</div> So, I thought that maybe ...

Finding number of nodes in PHP, DOM, XPath

I am loading HTML into DOM and then querying it using XPath in PHP. My current problem is how do I find out how many matches have been made, and once that is ascertained, how do I access them? I currently have this dirty solution: $i = 0; foreach($nodes as $node) { echo $dom->savexml($nodes->item($i)); $i++; ...