-1

I wanted to edit slider buttons of Sydney theme(wordpress) to have separate links for each button and I found the following JQuery code. This code works well but opens the links in the current page. Now, I want to edit this code to open the links in a new tab. How could I do it?

jQuery(function($) {

  //Define the new buttons. Delete the lines you don't need
  var button1 = '<a href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1
  var button2 = '<a href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2
  var button3 = '<a href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3
  var button4 = '<a href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4
  var button5 = '<a href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5

  //Hide the default button
  $('.slide-inner a').hide();

  //Add the new buttons. Delete the lines you don't need
  $('.slide-item:nth-of-type(1) .slide-inner').append(button1); //Slide 1
  $('.slide-item:nth-of-type(2) .slide-inner').append(button2); //Slide 2
  $('.slide-item:nth-of-type(3) .slide-inner').append(button3); //Slide 3
  $('.slide-item:nth-of-type(4) .slide-inner').append(button4); //Slide 4
  $('.slide-item:nth-of-type(5) .slide-inner').append(button5); //Slide 5
});
Satpal
  • 132,252
  • 13
  • 159
  • 168
Ali Kefayati
  • 325
  • 1
  • 2
  • 11

4 Answers4

2

Add target="_blank" to all link elements

   var button1 = '<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1
   var button2 = '<a target="_blank" href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2
   var button3 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3
   var button4 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4
   var button5 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5
Sajan
  • 813
  • 9
  • 14
2

target="_blank" is what you need:

   //Define the new buttons. Delete the lines you don't need
   var button1 = '<a href="http://www.google.com" target="_blank" class="roll-button button-slider">Read More</a>'; //Slide 1

etc..

for more information - have a look here: https://developer.mozilla.org/en/docs/Web/HTML/Element/a#Attributes

silicakes
  • 6,364
  • 3
  • 28
  • 39
2

You need to set target for that.

jQuery(function($) {

  //Define the new buttons. Delete the lines you don't need
  var button1 = '<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1
  var button2 = '<a target="_blank" href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2
  var button3 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3
  var button4 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4
  var button5 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5

  //Hide the default button
  $('.slide-inner a').hide();

  //Add the new buttons. Delete the lines you don't need
  $('.slide-item:nth-of-type(1) .slide-inner').append(button1); //Slide 1
  $('.slide-item:nth-of-type(2) .slide-inner').append(button2); //Slide 2
  $('.slide-item:nth-of-type(3) .slide-inner').append(button3); //Slide 3
  $('.slide-item:nth-of-type(4) .slide-inner').append(button4); //Slide 4
  $('.slide-item:nth-of-type(5) .slide-inner').append(button5); //Slide 5
});
Rakesh Yadav
  • 113
  • 7
1

use target=_blank attribute of html as

<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a>
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70