Setting a permanent link with jQuery

The problem with static web sites is that they cannot automatically generate a permanent link for their pages. Generally this link is inserted within the main title of the page, for example a blog post. Fortunately, we can easily overcome this problem by using jQuery. More precisely, we're going to generate a permanent link using the href property of the location object. Here's how:

$(document).ready(function() {

  var url = location.href;
  var permalink = '<a href="' + url + '"></a>';
  $('').each(function() {
    var $post = $(this);
    var $postTitle = $post.find('');


We use the wrapInner() method to wrap the textual content of our post title with the newly created permanent link. You can see the demo below.


Live demo

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.