jQuery: Change the hyperlink and the text
jQuery core : Exercise-9 with Solution
Write jQuery Code to change the hyperlink and the text of a existing link
Sample Data :
<a href="www.w3resource.com/sqlite/" id='tut'>SQLite Tutorial</a>
Change the hyperlink to -> www.w3resource.com/mysql/mysql-tutorials.php text -> MySQL Tutorial
Solution:
HTML Code:
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title>Change the hyperlink and the text of a existing link</title>
</head>
<body>
<a href="www.w3resource.com/PostgreSQL/tutorial.php" >PostgreSQL Tutorial</a>
</body>
</html>
JavaScript Code :
$("a").attr("href", "www.w3resource.com/mysql/mysql-tutorials.php");
$("a").text("MySQL Tutorial");
Live Demo:
See the Pen jquery-core-exercise-9 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Write a jQuery Code to add a tag at the beginning of the list item, containing the index of the list item.
Next: jQuery CSS
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/jquery-exercises/jquery-core-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics