$(document).ready(() => {
$('a#link1, a#link2').click((e) => {
$(e.target).toggleClass('active')
$('#content' + e.target.getAttribute('id')[4]).toggle()
e.stopPropagation()
})
$('#content1, #content2').click(e => e.stopPropagation())
$('body').click(() => [$('a#link1'), $('a#link2')].forEach($link => $link.hasClass('active') && $link.click()))
})