Open a link in a new tab on button click in Jquery

Open a link in a new tab on button click using Jquery

Posted by Luke Beeno on July 31, 2022

Open a link in a new tab on button click in Jquery

Open a link in a new tab on button click using Jquery

Posted by Luke Beeno on July 31, 2022

Here are the steps to take in order to open a link in a new tab on button click using Jquery.

Step 1. Identify button using id attribute "open-link"

Step 2. Add an onclick event listener to the button

Step 3. Add the window.open method to the event listener

Here is an example below: 

HTML

<button type="button" id="open-link">open tab</button>

JS

$( "#open-link" ).click(function() {
  window.open('https://google.com', '_blank');
});