-1

I have code like this:

<div id='my-div'></div>

When a user clicks on this div, I would like to open http://google.com in a new tab or window. I'm using jquery as follows:

$('#my-div').click(function() {
    // what do I put here?
});
tadasajon
  • 14,276
  • 29
  • 92
  • 144

1 Answers1

13

For a new window:

$('#my-div').click(function() {
   window.open("http://www.google.com", '_blank');
});

or for a new tab:

$('#my-div').click(function() {
   window.open('http://google.com');   
});
jmore009
  • 12,863
  • 1
  • 19
  • 34
  • Using either of these methods opens the link into a new tab and in the same window simultaneously. Any suggestions? – THRILLHOUSE Mar 18 '22 at 15:27