[jquery] go to link on button click - jquery

I have a script as below

$('.button1').click(function() {
    document.location.href=$(this).attr('id');
});

the button1 has variable unique ids. on click, the page must redirect to url "www.example.com/index.php?id=buttonid" but now the page is redirecting only to "button id".

I want to add the string "www.example.com/index.php?id=" before the current url. How can I make this possible?

This question is related to jquery dynamic-data response.redirect

The answer is


Why not just change the second line to

document.location.href="www.example.com/index.php?id=" + $(this).attr('id');

$('.button1').click(function() {
   document.location.href='/index.php?id=' + $(this).attr('id');
});

you can get the current url with window.location.href but I think you will need the jQuery query plugin to manipulate the query string: http://plugins.jquery.com/project/query-object


You need to specify the domain:

 $('.button1').click(function() {
   window.location = 'www.example.com/index.php?id=' + this.id;
 });