<div>
<h1 class="h1 myh1">Headline</h1>
</div>
(function($){
var var_h1 = $('h1')
$('div').on('click', function(event){
if (event.target == var_h1 ) {
alert('H1 was clicked')
}
})
})(jQuery)
When I click h1 nothing is happening.
How can I use event.target
and check if the element clicked is the variable var_h1
?
I don't wish to check a class if exist because this variable will be reused again and again. How can I using event.target
check for the variable var_h1
if clicked?
Thanks in advance.