Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: open

Question about jQuery selector lookup performance.

   
3:10 pm on May 29, 2012 (gmt 0)

5+ Year Member



Hi all,

With my project getting bigger by the minute, i'm worried about inadvertently reusing id's in html elements. So i thought i should fully qualifying a jQuery selector path to make sure i don't access the wrong elements.

Is there a marked performance hit increase when fully qualifying a jQuery selector path then just specifying the element id alone?

example:
$('#workorder-form #sa-table-1 tr #wi-UnitPrice') vs $('#workorder-form #wi-UnitPrice') vs $('#wi-UnitPrice')

I prefer to use the highest level id with the target id - $('#workorder-form #wi-UnitPrice') - because things don't break as easily when your changing mid level id's in the css script.

thanks.
12:44 am on May 30, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



If jQuery assumes id's are unique, it is likely to reduce $('#workorder-form #sa-table-1 tr #wi-UnitPrice') to $('#wi-UnitPrice'), that is ignore all prior to last hash.

Validating HTML better idea ?

Alternatively you could break the expression up

eg
var wform = $('#workorder-form');
var saTable = wform.find('#sa-table-1');
etc
there may be some time advantage here if there are multiple elements to identify within saTable
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month