Gomzy Gomzy - 6 months ago 14
HTML Question

how to trigger all anchor tag on button click?

sorry if title is wrong

i want to open all link on a single click

how to trigger all anchor tag on button click

thank you in advance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<div>
<a href="1.link">test</a>
<br />
<a href="2.link">test2</a>
<input type="button" id="bb" value="click">
</div>
<script>
$(function(){
$("#bb").click(function(){
$('a').click();
});
});
</script>
</body>
</html>

Answer

Try like following.

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