Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery :contains function limit to exact match

Using the JQuery :contains function to decide which option on a select is selected from a SESSION variable.

The contains function is matching the wrong option as their is an option 'PADI Open Water' and another 'PADI Open Water Scuba Instructor'

How do we limit it to match the exact content and no more?

$('option:contains("<?php echo $_SESSION['divelevel'];?>")').attr('selected', 'selected');
like image 744
RIK Avatar asked Mar 31 '11 14:03

RIK


1 Answers

Try using .filter(), to find the option you want.

$('option').filter(function(){
    return $(this).html() == "<?php echo $_SESSION['divelevel'];?>";
}).attr('selected', 'selected');
like image 150
Rocket Hazmat Avatar answered Sep 23 '22 22:09

Rocket Hazmat