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
Post a Comment