I have many elements that one of my JS widgets needs to create and add to the DOM often. They never change. So one option would be to store the HTML itself as a string in JS and use JQuery to create the elements from the string, then append it to the document: Another option is to write a function
Tag: dom
Change the Value of h1 Element within a Form with JavaScript
I have two forms on an HTML5 page. Each form has a name and an id. The second form has an h1 element, which also has a name and an id. How do I change the text of this h1 element on the second form using plain JavaScript? Answer Try: document.getElementById(“yourH1_element_Id”).innerHTML = “yourTextHere”;
Can you attach a handler function with arguments to an onclick event for a number of elements in a loop?
I am trying to set an onclick event for thumbnails that are dynamically populated from a database. I need to set the function to handle an argument, which is the id of the bigger picture the thumbnail represents. The code I have now sets all the thumbnails to point to #18. If you see in the for-loop, it is supposed
How can I exclude an element from a mouseover event with Javascript?
I’m basically trying to build the equivalent of the firebug inspector in the browser. I’m currently using the <body> as the container in this example: In the inspect method, I reposition and resize a semi-transparent fixed positioned element over the element returned from the event target. But this causes the mouseover event to subsequently inspect the overlay element itself. I
DOM change event for Opera
So far I found how to do it in Chrome, the DOMSubtreeModified event: Is there a JavaScript/jQuery DOM change listener? Apparently it works in Firefox and IE 9 too. Do you know solutions for detecting DOM changes in other browsers such as Opera? And maybe older versions if IE, because I’m sure the event above doesn’t work in IE 6-7-8…
In JavaScript e.target is not working as I expected
I have written some JavaScript that opens an element when an element is clicked. However I can’t get the: This is not working to how I want it because: You can open more than one of the showed elements when I only want one open at a time. When I click inside the element it closes, I only want it
how to get all parent nodes of given element in pure javascript?
I mean an array of them. That is a chain from top HTML to destination element including the element itself. for example for element <A> it would be: Answer A little shorter (and safer, since target may not be found):
How to move an iFrame in the DOM without losing its state?
Take a look at this simple HTML:
Let’…
Input Fires Keypress Event Twice
This question has been asked/answered (mostly) before, BUT I’ve tried three things to stop the event from bubbling but nothing has worked: (return false should take care of the other two, correct?) Here’s the html: And the JS (UPDATE CLEANED UP): }); I left the redundant stoppers in there but really shouldn’t return false simply kill the bubbling? (using Chrome).
When to use NodeIterator
Benchmark compares QSA & .forEach vs a NodeIterator Now either NodeIterator’s suck or I’m doing it wrong. Question: When should I use a NodeIterator ? In case you don’t know, DOM4 specifies what NodeIterator is. Answer It’s slow for a variety of reasons. Most obviously is the fact that nobody uses it so quite simply far less time has been