whatsnewsaes whatsnewsaes - 6 months ago 46
Javascript Question

Jquery if text contains specific text change sibling select value

I want to write some jquery that says if .email div contains "uic.edu" assign sibling select value to 2.

My code below is changing all selects on the page to a value of 2...How do I single out only the "selects" within .department-user that have the email which contains 'uic.edu'?

JS:

if ($(".department-user:contains('uic.edu')")) {
$(".department-user select").val("2");
}


HTML

<li class="department-user">
<div class="email">john@uic.edu</div>
<div class="quick-assign">
<select name="" id="">
<option value="0">Michigan</option>
<option value="1">california</option>
<option value="2">Chicago</option>
</select>
</div>
</li>

Answer
$(".department-user:contains('uic.edu') .quick-assign > select").val(2);