tapaljor tapaljor - 2 months ago 4x
jQuery Question

How create link in jQuery?

I have a jQuery notification. When I click on the notification it should go the intended page.

In PHP we can achieve that by doing following.

$link = 22;
echo "<a href=\"page2.php?id=link\">Click to read more</a>";

How to achieve such in JQuery? I have notification pop up and link variable ready.

var link = "home.php?destination=22";


You can create HTML element using jQuery

var link = "home.php?destination=22";

//Create anchor element
var anchor = $('<a />', {
  "href": link,
  "text": "Click to read more"

//Append the element
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<div id="dialog" title="Basic dialog">