[jQuery Tip] Traverse/Parse HTML String

When you are getting an HTML string from an external source (e.g. from an AJAX get result) and you want to rip out a certain part of the HTML source, you need to make sure that the ‘certain part’ is not at the top level of the HTML source.

For example, we have the following HTML string:

Hello

World

If we want to get the first paragraph element by using:

// data is the HTML source
$("p#first", data);

The above code won’t work, because the p tags are at the top level. Instead, we can simply wrap the HTML source with a div tag and that’ll do it. :)

Browser JavaScript and DOM Benchmark Tests: Firefox, Minefield, Safari, Webkit, Chrome, Chromium and Opera 10.5

Today Opera has released its latest and greatest version of Opera browser 10.5 Beta for Mac. It features speed enhancement as well as a unified Cocoa interface. Just how speedy is it exactly? Let’s test it out against other major browsers.

The benchmarks were run on my Macbook Pro (OS X 10.6.2, 2.53GHz CPU, 4GB RAM). I have performed three benchmark tests from Dromaeo - All JavaScript Tests, DOM Core Tests and JavaScript Library Tests. The following browsers are used:

  • Firefox 3.6
  • Minefield (Latest Firefox Nightly)
  • Safari 4.0.4
  • WebKit Latest Nightly
  • Chrome 5.0 Beta
  • Chromium Latest Nightly
  • Opera 10.5 Beta 1

The benchmark result (the higher the better):

Opera is smoking fast for pure JavaScript execution, on the other hand its DOM performance is significant lower than its competitors.

Very interesting result, hey? ;)