Skip to main content

Posts

Showing posts with the label dom

How to emulate Event.timeStamp

Event.timeStamp The timeStamp attribute must return the value it was initialized to. When an event is created the attribute must be initialized to the number of milliseconds that has passed since 00:00:00 UTC on 1 January 1970.

jQuery: How to select "from here until the next H2”?

I'm setting up a very straightforward FAQ page with jQuery. Like so: <h2>What happens when you click on this question?</h2> <p>This answer will appear!</p> This is all inside a very specific div, so I'll be selecting the header with $('#faq h2') . Simple, right? Click on the H2, and use this.next() to make the next paragraph show up. (The caveat with this page is that a non-programmer will be maintaining it, which is why I'm not using classes: there's no guarantee that any new entries would have the right classes in them.) So! The problem: <h2>What happens when you click on the next question?</h2> <p>That is an interesting conundrum.</p> <p>Because the maintainer is kind of long-winded</p> <p>and many answers will span a few paragraphs.</p> So how, without adding in div s and classes and whatnot, can I have my this.next() routine select everything between the question-that-was-

jQuery leaks solved, but why?

I am working on a large enterprise application with a LOT of JavaScript. Enough that I can't possibly go through and fix all the small circular references that have been created over its past 5 years of development. While researching solutions I came across this small jQuery hack/patch: http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/ and decided to try it. Amazingly, it works! sIEVE shows no leaks in the places I had previously identified them and the iexplore task is maintaining a more manageable memory footprint. My question is, why does this work? jQuery.remove calls .removeChild, which should get rid of the element, but apparently does not. The patch instead appends the target element onto a new garbage collector div, which it then clears. Why does the patch method of removal completely free up the memory but jQuery's remove function does not? I'm hoping to understand why this works in order to possibly improve the solution before

DOM Mutation event in JQuery or vanilla Javascript

Are there any DOM mutation events in JQuery or in vanilla Javascript that fire cross browser? To clarify, say I have a script on my page which inserts a div into the body. I don't have access to the script and I don't know when the div has been inserted. I was wondering if there's a DOM mutation event that I can add a listener for to know when the div has been inserted. I know I can use some kind of timer to periodically check for the div but I don't really like the overhead that this would impose. Source: Tips4all

How are JavaScript host objects implemented?

I was thinking about this today and I realized I don't have a clear picture here. Here are some statements I think to be true (please correct me if I'm wrong): the DOM is a collection of interfaces specified by W3C. when parsing HTML source code, the browser creates a DOM tree which has nodes that implement DOM interfaces. the ECMAScript spec has no reference of browser host objects (DOM, BOM, HTML5 APIs etc.). how the DOM is actually implemented depends on browser internals and is probably different among most of them. modern JS interpreters use JIT to improve the code performance and translate it to bytecode I am curious about what happens behind the scenes when I call document.getElementById('foo') . Does the call get delegated to browser native code by the interpreter or does the browser have JS implementations of all host objects? Do you know about any optimizations they do in regard to this? I read this overview of browser internals b

Pass mouse events through absolutely-positioned element

I'm attempting to capture mouse events on an element with another absolutely-positioned element on top of it. Right now, events on the absolutely-positioned element hit it and bubble up to its parent, but I want it to be "transparent" to these mouse events and forward them on to whatever is behind it. How should I implement this? Click here for an example page . All its divs flash on mousedown. Source: Tips4all

Convert String to XML Document in JavaScript

Saw this example on the jQuery examples page for Ajax: var xmlDocument = [create xml document]; $.ajax({ url: "page.php", processData: false, data: xmlDocument, success: someFunction }); How do I take a string like: var t = '<foo><bar>something</bar></foo>'; And convert that to a XML DOM object? cross-browser? UPDATE : Please see comments to karim79's answer. Source: Tips4all

jQuery: Move Table Row?

Say I had to links with up/down arrows for moving a table row up or down in order. What would be the most straightforward way to move that row up or down one position (using jQuery)? There doesn't seem to be any direct way to do this using jQuery's built in methods, and after selecting the row with jQuery, I haven't found a way to then move it. Also, in my case, making the rows draggable (which I have done with a plugin previously) isn't an option. Source: Tips4all

Getting content of partial html in DomDocument

I have a string: $string = 'some text <img src="www">'; I want to get the image source and the text. Here is what I have: $doc= new DOMDocument(); $doc->loadHTML($string); $nodes=$doc->getElementsByTagName ('img'); From $nodes->item(0) I get the image source. How can I get the the "some text"?