homepage Welcome to WebmasterWorld Guest from 54.226.0.225
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Question about jQuery selector lookup performance.
nelsonm




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

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.

 

daveVk




msg:4459256
 12:44 am on May 30, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved