javascript - Why can I not select both input elements? -
this question has answer here:
- jquery id selector works first element 6 answers
i'm trying set value input element(s) match id.
but jquery.each picking first/one input element.
i'm trying perform ajax post , need both these id have same value.
html
@html.hiddenfor(u => u.transid) //<input id="transid" name="transid" type="hidden" value="0"> @html.dropdownlistfor(u => u.transid, model.transmodes) //<input id="transid" name="transid" value="0">
script
$("#transid").each(function () { $(this).val("2") alert($(this).val()); });
cheers
an id
must unique in html. if want name several elements same use class
instead.
<input class="transid" name="transid1" type="hidden" value="0"> <input class="transid" name="transid2" value="0">
script
$(".transid").each(function () { $(this).val("2") alert($(this).val()); });
Comments
Post a Comment