How to use a reference variable in a jQuery? -


i learned using reference variable faster using $() every line of code (see previous question): jquery - okay use $('#elementid') everytime?. question how can use reference variable maximize power of jquery? please see example below:

without reference variable:

var valueofselected = $('#selectelementid option:selected').val(); 

with reference variable (pseudo-code):

var selectelement = $('#selectelementid'); var valueofselected = $(selectelement).selectedoption.val(); 

note selectedoption.val() pseudo-code here. there such function anyway?

you can use .find() find nested option.

var selectelement = $('#selectelementid'); var valueofselected = selectelement.find('option:selected').val(); 

...but because select element, can use val()[docs] method directly.

var selectelement = $('#selectelementid'); var valueofselected = selectelement.val(); 

this give value of selected option.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -