2

I have two div and I want to open these two div in new tab by using one click.

<a href="http://google.com"><div id="google">This is Google.</div></a>
<a href="http://youtube.com"><div id="youtube">This is YouTube.</div></a>
kenphanith
  • 61
  • 1
  • 10

5 Answers5

2

Something like this should do that

$('a').on('click', function(e) {
    e.preventDefault();
    $('a').each(function() {
        window.open(this.href, '_blank');
    });
});

Here's a demonstration using a button

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

Add 'target=_blank' to in <a> tag .

    <a href="http://google.com" target='_blank'><div id="google">This is Google.</div></a>
    <a href="http://youtube.com" target='_blank'><div id="youtube">This is YouTube.</div></a>
Sardor Dushamov
  • 1,665
  • 3
  • 17
  • 44
0

Use javascript for both

<script>
  $('#googel,#youtube').click(function()
  {
     // your commands...
  })
</script>
0

Without javascript, it's not possible to open two links in two different tabs on one click. So my suggestion is to wrap those divs in a parent div and do some javascript.

var wrapper = document.getElementById('wrapper');

wrapper.onclick = function(){
  window.open('http://google.com', '_blank');
  window.open('http://youtube.com', '_blank');
};
#wrapper{
  cursor: pointer;
}

#wrapper:hover{
  background-color: #0ff;
}
<div id="wrapper">
  <div id="google">This is Google.</div> 
  <div id="youtube">This is YouTube.</div>
</div>
sajithrw
  • 73
  • 7
0

As you can try this:

$("#google, #youtube").click("Do your work");

For more: Reference-1 & Reference-2

Community
  • 1
  • 1
Suvro
  • 352
  • 2
  • 13