-4

//does not work
$("#TextBoxID1").attr("value","HI Value Change")
//work fine
$("#TextBoxID2").val("HI Value Change")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<input type="text" id="TextBoxID1"/>
<input type="text" id="TextBoxID2"/>

I want to set value for textbox but jquery .attr() does not work while if I try .val() it works fine.

I am using angular-autocomplete and in its input control I want to set the value using jquery it works but I just want to know why .attr() does not work.

George
  • 6,116
  • 2
  • 24
  • 36
Mukesh Gupta
  • 59
  • 1
  • 7

1 Answers1

1

It's maybe just a problem with your internet browser.

The .attr() method works well for your example:-

https://jsfiddle.net/376a1hjj/

Try to run your code with another browser like chrome or firefox if it isn't the case or update your current browser.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Xisabla
  • 24
  • 4