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? -

file - Python: AttributeError: 'str' object has no attribute 'readlines' -

c# - Get the Class name in a class with atribute inside a attribute method -