

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery .val change doesn't change input value?
For this, you need to use attr(). The attr() method can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements.
Following is the JavaScript code −
Example
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type = 'text' value = 'http://www.example.com' id = 'myURL' /> <script> $('#myURL').attr('value', 'http://www.facebook.com'); </script> </body> </html>
To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VSCode Editor.
Output
Look at the above sample output the URL has been changed from domain example to domain facebook..
- Related Questions & Answers
- Change input type value attribute in jQuery
- jQuery change() with Example
- Change value of input on form submit in JavaScript?
- How to change the value of an attribute using jQuery?
- How to change CSS using jQuery?
- Change max_heap_table_size value in MySQL?
- Change the size of Bootstrap input groups
- Python3 - Why loop doesn't work?
- Why doesn't JavaScript support multithreading?
- How to change the background color using jQuery?
- How to change the background image using jQuery?
- Resolve the error Column count doesn’t match value count in MySQL?
- MySQL system variable table_type doesn't work?
- Why Training Doesn’t Help Your Organization!
- How to change text inside an element using jQuery?
Advertisements