javascript - Change all values of input types with same id -
what @ moment got problem wanna change each elements value id matches input type. please @ jsfiddle, should clear alot you. thing values won't change of input types changes first input type of id. tried using .each function didn't help.
html
<input type="text" id="first" value="tesdafsdf" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" /> <input type="text" id="second" />
jquery
$('#first').keyup(function() { updatesearch(); }); var updatesearch = function() { $('#second').each(function(index, value) { this.value = $('#first').val(); }); }; //change values testing purpose updatesearch();
id used uniquely identify element id of element must unique.
it must unique in document, , used retrieve element using getelementbyid. other common usages of id include using element's id selector when styling document css.
when have group multiple element 1 of easiest way use class attribute.
when use id selector, return first element matching id rest of elements ignored.
so
$('.first').keyup(function() { updatesearch(); }); var updatesearch = function() { $('.second').val($('.first').val()); }; //change values testing purpose updatesearch();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="first" value="tesdafsdf" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" /> <input type="text" class="second" />
Comments
Post a Comment