I know how to add two jQueries together using add()
However, for a project I am working on, it has become a performance bottleneck. I fiddled around and came up with an alternative, which gives me the same results at a great performance increase (~60ms versus 1000ms in this fiddle):
http://jsfiddle.net/jedierikb/rkAP4/1/
var t = $("#test");
var tKids = t.children( );
var j = $("#jest");
var jKids = j.children( );
var z,
zMax = 30000;
var time1 = new Date();
for (z=0; z<zMax; z++)
{
var opt1 = tKids.add( jKids );
}
var time2 = new Date();
for (z=0; z<zMax; z++)
{
var i,
iMax,
allKids = [];
for(i = 0, iMax = tKids.length; i < iMax; i++)
{
allKids.push( tKids[i] );
}
for(i = 0, iMax = jKids.length; i < iMax; i++)
{
allKids.push( jKids[i] );
}
var opt2 = $( allKids );
}
var time3 = new Date();
console.log( (time2-time1) + " v " + (time3-time2) );
Note: I do not need the benefits of add such as guaranteed dom-element ordering and removal of duplicates.
I am wondering if there is a way to make this approach cleaner or more compact than all of the iterating I am doing. Or maybe there is a better approach all together.