Tag: dom

Determine what Javascript function is called when you click an element

Is there a way to determine what Javascript function is called when you click on an item in a HTML page that has JS binded to the click event (added using jQuery, not the onClick tag attribute) ? Obviously, the website is not mine and the code is minified.

How to delete all text inside a DOM element

I have a div that looks like this. <div class=”main”> <div class=”slide”></div> <div class=”thumbs”> Text 1 <img src=”https://cdn1.iconfinder.com/data/icons/flat-business-icons/128/stack-128.png”/> <div></div> <p>Text 2</p> <div> <p>Text 3</p> <div><p>Text 4</p></div> </div> </div> </div> And I want to delete all text inside the div with the class thumbs. I tried this, but unfortunately, it only delete “Text 1” and not […]

How can I get a reference to a node directly after it is appended?

I have a situation where I’m appending a node inside an element and would like a reference to it right away. At the moment I do something along these lines: var children = $(“#elem”).append(“<p>hello</p>”).children(); var current = children[children.length -1] Can this be done more cleanly with jQuery? I know, I can write a helper function, […]

Geting reference to many elements having the same id using Javascript

Suppose to have the following: <div> <div id=”element”></div> <div id=”element”></div> <div id=”element”></div> <div id=”element”></div> <div id=”element”></div> <div id=”element”></div> <div id=”element”></div> </div> Ok. This html piece is placed somewhere in the code… I must collect all tags having the element id. How can I achieve this in javascript? getElementById allows me to retrieve only one element… […]

does innerHTML work with XML Elements?

According to JavaScript: The Definitive Guide: “Despite its name, innerHTML can be used with XML elements as well as HTML elements”. However, when I actually attempt to access the innerHTML property of an XML Element object, undefined is returned: var xml = $.ajax({url: “test.xml”, async: false}).responseXML.documentElement; console.log(xml.innerHTML); // displays “undefined” in console log What is […]

html5, what is isContentEditable?

chrome supports the isContentEditable property (lists it in the “Inspect Element”), but reports false for INPUT, FORM – actually, everything. too me, for example, seems that INPUT, non-readonly, should be true. does anybody know what’s going on?

How do I “refresh” element in DOM?

I’ve got an empty DIV element in which I append images by using function createElement(“img”) and append them with appendChild. So now I’ve got DIV element full of images. I would like to use one button to clean this DIV and add new images in it simultaneously. Thanks for your help

What is the implementation of GetElementByID()?

Can somebody please explain to me the internal implementation of HTML getElementById() method ? Is it traversing whole DOM tree to find the specified element or is it intelligent enough to look for near-by elements first ? Thank you

JQuery .click not working as I expected

I have a question about the .click function in Jquery. I have this code: for (var i = 0; i < 5; i++) { var divTest = $(‘<div></div>’); divTest.text(“My Div ” + i); divTest.click(function() { alert(“Alert: Div ” + i); }); $(‘#myTest’).append(divTest); }‚Äč I expected to add five divs to the “myTest” element and for […]

stopPropagation: element.addEventListener vs onclick attribute

I’m playing with stopPropagation, adapting code from an MDC doc. Here’s the question: Everything works fine if I do what they did and use element.addEVentListener(“click”, fname). But, when I try to attach the function with the element’s onclick attribute ( <div onclick=”fname();”> ), propagation does not stop. And if I use <div onclick=”function(ev) {fname();}”>, fname() […]