Click outside of element native javascript

A simple example of how to track a click outside of element.

var test_1 = document.getElementById("id1");
var test_2 = document.getElementById("id2");
var test_3 = document.getElementById("id3");

window.addEventListener('click', function(e){

    if (!test_1.contains(e.target) && !test_2.contains(e.target)){
        console.log("outside of #id1 and #id2");
    }

    if (!test_3.contains(e.target)){
        console.log("outside of #id3");
    }

});