Showing posts with label Hypertext. Show all posts
Showing posts with label Hypertext. Show all posts

Thursday, 13 May 2021

Dynamically create hypertext and hyperlink using JQuery.

 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>

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...