whatsnewsaes whatsnewsaes - 2 years ago 182
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'?


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


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

Answer Source
$(".department-user:contains('uic.edu') .quick-assign > select").val(2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download