tapaljor
tapaljor

Reputation: 257

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";

Upvotes: 2

Views: 1701

Answers (2)

Satpal
Satpal

Reputation: 133453

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
$('#dialog').append(anchor).dialog();
<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">
  
</div>
 

Upvotes: 4

dhamo dharan
dhamo dharan

Reputation: 762

you can achieve it using window.location.href in java script.

<button onclick="myFunction()">Click me to read more</button>
<script>
function myFunction() {
    window.location.href = 'home.php?destination=22';
}
</script>

Upvotes: 0

Related Questions