-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?
});
1
  • window.open(strTheURL) Commented Jan 13, 2015 at 22:12

1 Answer 1

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');   
});
Sign up to request clarification or add additional context in comments.

1 Comment

Using either of these methods opens the link into a new tab and in the same window simultaneously. Any suggestions?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.