jquery - How to use text of option to find value of the same -


i have multiple select option id name test , has 1 option b.

$('#test').find('option[text="b"]').val();

here if use getting correct result i.e. value of option. problem in jquery don't have b instead of have variable has value b.please tell me guys how can use variable in place of b in jquery.

i tried using this

var x=myvariable

$('#test').find('option[text=x]').val();

thanks

you can concatenate variables this, try:

$('#test').find('option[text="'+x+'"]').val() 

Comments

Popular posts from this blog

ios - Is 'init' forbidden as *part* of a variable name? -

angular - Angular2 Router: Cannot find primary outlet to load 'HomeComponent' -

qt - Microsoft FTP Service 451 The parameter is incorrect -