I have an element that when clicked, shows an inner text (which is initially set to display: none
). I want to add a span inside that inner text to close that text, but $(event.target)
is not working in this case and I'm not sure why. It's also worth noting that the links inside that text do not work either.
HTML
<div class="blog-block-2">
<div class="blog-entry-language-2">
<h2> Test Header</h2>
</div>
<div class="blog-entry-main-2">
<div class="blog-entry-image-2"></div>
<div class="blog-entry-text-wrap-2">
<h2>Test header <span class="close">X</span></h2>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.
</p>
<p>
Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. <a href="#">Aenean dignissim</a> pellentesque felis.
</p>
<div class="overlay"></div>
</div>
</div>
<div class="blog-entry-extra-2">
<h1> Extra tag </h1>
</div>
</div>
JS
$(".blog-block-2").on("click",function(event){
var target = $( event.target );
if( target.is("span")){
console.log("clicked outside");
hideText();
} else {
showText();
console.log("clicked");
}
})
JsFiddle: