Adding an onclick function to go to url in JavaScript? Adding an onclick function to go to url in JavaScript? javascript javascript

Adding an onclick function to go to url in JavaScript?


Try

 window.location = url;

Also use

 window.open(url);

if you want to open in a new window.


Simply use this

onclick="location.href='pageurl.html';"


In jquery to send a user to a different URL you can do it like this:

$("a#thing_to_click").on('click', function(){     window.location = "http://www.google.com/";    });

this way will work too but the above is the newer more correct way to do it these days

$("a#thing_to_click").click(function(e){         e.preventDefault();         window.location = "http://www.google.com/";    });