jquery - Which is the more efficient way for SELECT onchange? -


in jquery, have 2 ways select onchage:

1. use .change specifying name

html:

<select name="a">     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option> </select> 

jquery:

$('select[name=a]').change(function(){     alert($(this).val()); }); 

2. use .change specifying id

html:

<select id="a">     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option> </select> 

jquery:

$('#a').change(function(){       alert($(this).val()); }); 

so, given smaller or larger list of elements, 1 faster/more efficient when using jquery?

what best practice?

first of there lots of other ways select element (including select element) in jquery.
selecting elements id better supposed unique , gives results faster


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -