Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (20.3k points)

I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going on.

var d = document;

var odv = d.createElement("div"); = "none";

this.OuterDiv = odv;

var t = d.createElement("table");

t.cellSpacing = 0;

t.className = "text";


I would like to know if there is a better way to do this using jQuery. I've been experimenting with:

var odv = $.create("div");


// And many more

But I'm not sure if this is any better.

1 Answer

0 votes
by (40.7k points)

Here is an example:

this.$OuterDiv = $('<div></div>')



        .attr({ cellSpacing : 0 })



  • Try this for jQuery 1.4, 1.5, 1.6

              Chrome 11  Firefox 4   IE9

<div>            440ms      640ms    460ms

<div></div>      420ms      650ms    480ms

createElement    100ms      180ms    300ms

  • For jQuery 1.3 use this:

                Chrome 11

<div>             770ms

<div></div>      3800ms

createElement     100ms

  • For jQuery 1.2 try this:

                Chrome 11

<div>            3500ms

<div></div>      3500ms

createElement     100ms

Related questions

Browse Categories