javascript - eq(0) is not a valid selector with $.each -
<select class="qty"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <select class="qty"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select>
i have 2 select
tags , want update them array. means changing selected correct value, why in attempt below :eq()
not working loop?
selectedarr = [2,3]; $.each(selectedarr,function(i,obj){ console.log(obj); $('.qty:eq(' + + ')').prop('selected', true); });
there's few things wrong here:
$('.qty:eq('+i+')').prop('selected',true)
settingselected
property on<select>
element - not<option>
element- you aren't selecting appropriate option array according
selectedarr
i this:
var selectedarr = [2, 3]; $.each(selectedarr, function(i, obj) { $('.qty:eq(' + + ')').val(obj); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select class="qty"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <select class="qty"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select>
Comments
Post a Comment