Gomzy Gomzy - 6 months ago 12
jQuery Question

how to trigger all anchor tags on click of a button?

sorry if title is wrong

i want to open all the links on a single click

thank you in advance



$(function(){
$("#bb").click(function(){
$('a').click();
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<body>
<div>
<a href="1.link">test</a>
<br />
<a href="2.link">test2</a>
<br>
<input type="button" id="bb" value="click">
</div>

</body>




Answer

Try like following.

$("#bb").click(function () {
    $('a').each(function() {
        window.open($(this).attr('href'), '_blank');
    });
});