Tag: dom

How do I check if an element is really visible with JavaScript?

This question already has an answer here: Check if element is visible in DOM 15 answers

How to get the title of HTML page with JavaScript?

How can I get the title of an HTML page with JavaScript?

how to compare two elements in jquery

This question already has an answer here: How can I test if two jQuery wrapped DOM elements are the same? [duplicate] 3 answers

How to check in Javascript if one element is contained within another

How can I check if one DOM element is a child of another DOM element? Are there any built in methods for this? For example, something like: if (element1.hasDescendant(element2)) or if (element2.hasParent(element1)) If not then any ideas how to do this? It also needs to be cross browser. I should also mention that the child […]

How to replace DOM element in place using Javascript?

I am looking to replace an element in the DOM. For example, there is an “A” element that I want to replace with a “SPAN” instead. How would I go and do that?

JavaScript DOM remove element

I’m trying to test if a DOM element exists, and if it does exist delete it, and if it doesn’t exist create it. var duskdawnkey = localStorage[“duskdawnkey”]; var iframe = document.createElement(“iframe”); var whereto = document.getElementById(“debug”); var frameid = document.getElementById(“injected_frame”); iframe.setAttribute(“id”, “injected_frame”); iframe.setAttribute(“src”, ‘http://google.com’); iframe.setAttribute(“width”, “100%”); iframe.setAttribute(“height”, “400”); if (frameid) // check and see if iframe […]

Get element at specified position – JavaScript

Using Javascript how can I identify the element at a given position? Basically I’m looking to write a function that takes two input parameters (the x and y coordinates) and returns the html element at the position on the screen represented by the parameters.

Get elements by attribute when querySelectorAll is not available without using libraries?

<p data-foo=”bar”> How can you do the equivalent to document.querySelectorAll(‘[data-foo]’) where querySelectorAll is not available? I need a native solution that works at least in IE7. I don’t care about IE6.

Detect element content changes with jQuery

change() function works and detects changes on form elements, but is there a way of detecting when a DOM element’s content was changed? This does not work, unless #content is a form element $(“#content”).change( function(){ // do something }); I want this to trigger when doing something like: $(“#content”).html(‘something’); Also html() or append() function don’t […]

Retrieving the text of the selected <option> in <select> element

In the following: <select id=”test”> <option value=”1″>Test One</option> <option value=”2″>Test Two</option> </select> How can I get the text of the selected option (i.e. “Test One” or “Test Two”) using JavaScript document.getElementsById(‘test’).selectedValue returns 1 or 2, what property returns the text of the selected option?