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>
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>
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
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>
Use javascript for both
<script>
$('#googel,#youtube').click(function()
{
// your commands...
})
</script>
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>
As you can try this:
$("#google, #youtube").click("Do your work");
For more: Reference-1 & Reference-2