javascript - JQuery converting "option:contains" into an exact string value -
right getting select
option's value
(literal value
attribute) jquery, problem takes first value finds "contains" keyword.
for example, if had select
2 options: silver division (value=1
) , silver (value=2
), if called following line of code return (value=1
) rather (value=2
)
var ranking = "silver"; // hard-coded example var setindex = $("#userelo" +" > option:contains(" + ranking + ")").val();
q: have been trying search, no success, option:equals
looks exact string matches. have tried various test-and-guess things following.
var setindex = $("#userelo" + id + " > option:contains" + ranking).val(); var setindex = $("#userelo" + id + " > option[text=" + ranking + "]").val(); var setindex = $("#userelo" + id + " > option[text=" + ranking).val();
here jsfiddle demo on simple scale showing silver division , silver issue.
i running out of ideas though, if know of syntax solution that'd awesome!
thanks!
you'll need select of options may potentially match, use filter()
function narrow them down match text want. should it:
var ranking = "silver"; var setindex = $("#userelo > option").filter(function() { return $(this).text() === ranking; }).val();
Comments
Post a Comment