dynamic data - go to link on button click - jquery -


i have script below

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

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

i want add string "www.example.com/index.php?id=" before current url. how can make possible?

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

first of using window.location better according specification document.location value read-only , might cause headaches in older/different browsers. check notes @mdc dom document.location page

and second - using attr jquery method id bad practice - should use direct native dom accessor this.id value assigned this normal dom element.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -