you can't manipulate tabs via javascript (you can ask a link to open in a new window, you just can't tell it to open in a tab). what you might want to try if you want to try is something like this:
$('button').click(function() {
$('a').each(function() {
window.open($(this).attr('href') );
});
});
essentially, when <button>
is clicked, for each <a>
element, pass the href
value to window.open. or basically, piles of open windows assuming you have no pop up blocker :)
your current code basically says, when you press <button>
, activate the onclick()
handler of all <a>
elements.
edit: in response to comments, compare this code that mimics the OP's functionality:
$('a').click(function() {
// assign an event to a.onclick
window.open($(this).attr('href') );
});
$('button').click(function() {
// when we press <button>, trigger a.onclick
$('a').click();
});
because we declared an onclick()
functionality first, we now have the same behaviour as my original code. (piles of open windows)