user1765862 user1765862 - 1 year ago 108
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."

Answer Source

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

$('#Requester').attr("data-val-required","The Requested value field is required.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download