dom

Javascript Removing Whitespace When It Shouldn't?

I have a HTML file that has code similar to the following. <table> <tr> <td id="MyCell">Hello World</td> </tr> </table> I am using javascript like the following to get the value document.getElementById(cell2.Element.id).innerText This returns the text "Hello World" with only 1 space between hello and world. I MUST kee...

Using jQuery accordion with strange markup.

I have this HTML structure and want to convert it to an accordion. <div class="accor"> <div class="section"> <h3>Sub section</h3> <p>Sub section text</p> </div> <div class="section"> <h3>Sub section</h3> <p>Sub section text</p> </div> <div class="section"> <h3>Sub section</h3> ...

How can I determine if a dynamically-created DOM element has been added to the DOM?

According to spec, only the BODY and FRAMESET elements provide an "onload" event to attach to, but I would like to know when a dynamically-created DOM element has been added to the DOM in JavaScript. The super-naive heuristics I am currently using, which work, are as follows: Traverse the parentNode property of the element back until ...

How to get the new value of an HTML input after a keypress has modified it?

I have an HTML input box <input type="text" id="foo" value="bar"> I've attached a handler for the 'keyup' event, but if I retrieve the current value of the input box during the event handler, I get the value as it was, and not as it will be! I've tried picking up 'keypress' and 'change' events, same problem. I'm sure this is simple...

Safe, universal, way to use addEventHandler in Javascript?

Before I get into the details of this problem, I'd like to make the situation clear. Our web analytics company works as a consultant for large sites, and (other than adding a single SCRIPT tag) we have no control over the pages themselves. Our existing script installs handlers using "old" way (a fancy version of element.onclick = blah; ...

Get relative position between 2 DOM elements using JavaScript

I've implemented a set of draggable elements that can be dropped into some containers using jQuery. What I need is an animation that moves an element to a specific container without user interaction. The problem is that the elements and the drop containers are in completely different parts of the DOM and mostly positioned using float. A...

Unique element ID, even if element doesn't have one

I'm writing a GreaseMonkey script where I'm iterating through a bunch of elements. For each element, I need a string ID that I can use to reference that element later. The element itself doesn't have an id attribute, and I can't modify the original document to give it one (although I can make DOM changes in my script). I can't store the ...

What is a callback function and how do I use it with OOP

I want to use the php simple HTML DOM parser to grab the image, title, date, and description from each article on a page full of articles. When looking at the API I notice it has a set_callback which Sets a callback function. However im not sure what this does or how I would use it? In one of the examples its used to call a function whic...

How can I manipulate the DOM from a string of HTML in C#?

For the moment the best way that I have found to be able to manipulate DOM from a string that contain HTML is: WebBrowser webControl = new WebBrowser(); webControl.DocumentText = html; HtmlDocument doc = webControl.Document; There are two problems: Requires the WebBrowser object! This can't be used with multiple threads; I need som...

How to access HTML element without ID?

For instance in the snippet below - how do I access the h1 element knowing the ID of parent element (header-inner div)? <div id='header-inner'> <div class='titlewrapper'> <h1 class='title'> Some text I want to change </h1> </div> </div> Thanks! ...

PHP: Removing an attribute from a DOMNode object

I've got a DOMNode object that has some attributes. $Node->attributes is a DOMNamedNodeMap, which has no methods for removing one of the entries in the map. The DOMNode class also has no methods for removing attributes from an element. I've looked through a number of the other related classes and none of them seem to provide a mechani...

How do I view the contents of an IXMLDOMElementPtr when building an XML file?

I'm using IXMLDOM in MSXML 6 to build an XML file in a C++ MFC application. Is there a way to see the contents of the xml document while it is in memory? For example, an XPATH query is failing about halfway through creating the file. How would I view the entire contents of the xml doc? Thanks! ...

Can I target an element before it's closed?

I'm wanting to add a class to the body tag without waiting for the DOM to load, but I'm wanting to know if the following approach would be valid. I'm more concerned with validity than whether the browsers support it for now. <body> $("body").addClass("active"); ... </body> Thanks, Steve ...

How do I select an item by its text value in a dropdown using jQuery?

If I had the following select, and did not know the value to use to select an item in advance like in this question or the index of the item I wanted selected, how could I select one of the options with jQuery if I did know the text value like Option C? <select id='list'> <option value='45'>Option A</option> <option value='23'>Option B<...

Why are hidden form elements still read by JAWS?

The Situation I have an area of the screen that can be shown and hidden via JavaScript (something like "show/hide advanced search options"). Inside this area there are form elements (select, checkbox, etc). For users using assistive technology like a screen-reader (in this case JAWS), we need to link these form elements with a label or ...

is it normal for image inputs to be omitted from the DOM in document.forms[x].elements?

I've found that given a form in a HTML page like this: <form name="form"> <input type="image" name="foo" src="somewhere.gif" alt="image" value="blah"/> <input type="text" name="bar" value="blah"/> </form> When accessing the elements via the DOM in Javascript, there is no element for the image input! It is just omitte...

count immediate child div elements using jQuery

Hi, I have the following HTML node structure: <div id="foo"> <div id="bar"></div> <div id="baz"> <div id="biz"> </div> <span><span> </div> How do I count the number of immediate children of "foo", that are of type "div". In the example above, the result should be two ("bar" and "baz"). Cheers, Don ...

How can javascript determine the type of an html element?

I feel like this should be really easy to do, but I'm stumped. I need a way for Javascript to determine the type of an HTML element. It has the id, but the element itself could be a div, a form field, a fieldset, etc. Can anyone tell me how to do this? ...

How to pass arguments to addEventListener listener function?

The situation is somewhat like- var someVar; someVar = some_other_function(); someObj.addEventListener("click", function(){ some_function(someVar); }, false); The problem is that the value of someVar is not visible inside the listener...

Remove a child with a specific attribute, in SimpleXML for PHP

I have several identical elements with different attributes that I'm accessing with SimpleXML: <data> <seg id="A1"/> <seg id="A5"/> <seg id="A12"/> <seg id="A29"/> <seg id="A30"/> </data> I need to remove a specific seg element, with an id of "A12", how can I do this? I've tried looping through the seg elements an...