Creating hypertext and hyperlink is a very easy task in JQuery. Using .append() function, we can create hypertext and using .attr(), we can create hyperlink. See how.
$("a").append(" <b>Link created, click here</b>."); //append/create link to hyper text
The above function will append/create a hypertext to anchor the link.
$("a").attr("href", "https://arvindignou.blogspot.com"); //create hyperlink
The above .attr() funntion will create link/hyperlink of anchor tag.
Complete example:-
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("a").append(" <b>Link created, click here</b>."); //append/create link to hyper text
$("a").attr("href", "https://arvindignou.blogspot.com"); //create hyperlink
});
});
</script>
</head>
<body>
<a href=""></a> <!- dynamically hypertext and hyperlink will be created here-!>
</br>
<button id="btn1">Create Hyperlink and Hypertext</button>
</body>
</html>
No comments:
Post a Comment