1

I have DOM like below:

<body>
<table>
<tbody>
<tr></tr>
</tbody>
</table>
<input type="text" class="pi" value=""><br>
<input type="text" class="vi" value="">
<button>users</button>
</body>

When user clicks on button it appends new 'td' to 'tr'. It works good. Problem: On 'a' click I want to open two links. The best would be when first redirects current page to another and second opens seperated window. I tried to change 'a' on another tags, but did not help.

$('button').click(function () {
var pic = $('input[type="text"].pi').val();
var vid = $('input[type="text"].vi').val();
var cont = '<td><a data-big-image="' + vid + '" href="#"><img src="' + pic + '"></a></td>'
$('table').children('tbody').children('tr').last().append(cont);
});


$('a').click(function(e) {
e.preventDefault();
var bigImage = $(this).data('big-image');
window.open(bigImage);
window.open('xyz');
});
gorrch
  • 521
  • 3
  • 16
  • This will help you for sure https://stackoverflow.com/questions/7064998/how-to-make-a-link-open-multiple-pages-when-clicked and https://stackoverflow.com/questions/5566970/html-on-one-click-open-2-pages?answertab=active#tab-top – A l w a y s S u n n y Oct 22 '17 at 16:39
  • I have seen both and used snippet from first. – gorrch Oct 22 '17 at 17:05

1 Answers1

1
  1. Make a link like it's normally done
  2. Next place an inline element (ex. <b>, <span>, etc) inside the link
  3. Then add an inline attribute event handler to the new element.

    <a href="https://google.com" target="_blank">
      <b onclick="location.href='1st_location.html">GO</b>
    </a>
    

Demo

(does not work due to SO's security measures, see PLUNKER)

 <a href="https://google.com" target="_blank">
<b onclick="location.href='https://example.com';">GO</b></a>
zer00ne
  • 41,936
  • 6
  • 41
  • 68