Skip to content
Advertisement

Tag: dom

Difference between document.URL and location.href

I know that document.URL can not be set, while location.href can. But the Document indicates: URL is a replacement for the DOM Level 0 location.href property. So when would we use document.URL? Answer You can get the document.URL, but you can not set it. You can both get and set the location.href. In some webbrowsers, you are able to set

Table Row’s OnClick Event is Propagated to all Contained Elements?

I’ve run into some interesting code in our legacy application running under Internet Explorer. Consider the following: So, here’s where I’m stumped. When the user selects an item from the SELECT element, the ONCLICK event is firing, and the following are true: this evaluates to Window Window.event.srcElement evaluates to an array of ‘OPTION’ elements There doesn’t seem to be a

using javascript’s .insertBefore to insert item as last child

I so miss jQuery. I’m working on a project where I need to get my hands dirty with good ‘ol plain Javascript again. I have this scenario: Via javascript, I want to be able to insert a new node before or after any of those children. While javascript has an insertBefore, there is no insertAfter. Insert before would work fine

What is the DOM and BOM in JavaScript?

What is the DOM and BOM in JavaScript? If someone could explain these in layman terms it would be great! I like to get a deeper understanding of these. Answer The BOM (Browser Object Model) consists of the objects navigator, history, screen, location and document which are children of window. In the document node is the DOM (Document Object Model),

Remove all child elements of a DOM node in JavaScript

How would I go about removing all of the child elements of a DOM node in JavaScript? Say I have the following (ugly) HTML: And I grab the node I want like so: How could I remove the children of foo so that just <p id=”foo”></p> is left? Could I just do: or should I be using some combination of

Append Style to DOM not Replacing Existing

How can I append style element to DOM without eliminating existing style on the item (eg color, text-align, etc)? The event calls the function, but the problem is ‘Style’ gets completely replaced with the single item instead. I have simple code triggered on the event: Answer Which browser are you using? In Chrome, this works for me: When I click

Firing DOM mouse events programmatically from JavaScript

Is it possible to programmatically fire mouse events in DOM? My sample case would be the following: Whenever the user clicks the div over an iframe, I would like to somehow propagate the event to the iframe, too. (Here we assume that the iframe src is in the same domain.) Answer Whilst you can inject events into browsers’ event-handling systems

jQuery: how to change tag name?

jQuery: how to change tag name? For example: I need Yes, I can Create DOM element <div> Copy tr content to div Remove tr from dom But can I make it directly? PS: results in DOMException. Answer You can replace any HTML markup by using jQuery’s .replaceWith() method. example: http://jsfiddle.net/JHmaV/ Ref.: .replaceWith If you want to keep the existing markup,

Advertisement