user1765862 user1765862 - 9 months ago 27
Javascript Question

append attributes to input element using jquery

If I have input element rendered like this

<input id="Requester_Value" class="form-control ui-autocomplete-input valid" type="text" value="" name="Requester.Value" autocomplete="off" aria-invalid="false">

how can I using jquery add attributes to this input element

data-val-required="The Requested value field is required." data-val-number="The field Requester must be a string."


If you want to add an attribute to an element try.

$('#Requester').attr("data-val-required","The Requested value field is required.");