Reputation:
$(document).on('click', $('[data-what="abc"]'), function() {
console.log('323');
$(this).hide();
});
.title{
background:gold;
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='title' data-what='abc'>title</div>
console.log - works.
element.hide - doesn't work
Any help?
Upvotes: 0
Views: 15
Reputation: 9127
It doesn't work because this
is the element the event was bound to: document
. You're not trying to hide the whole document.
Try
$(document).on('click', $('[data-what="abc"]'), function(event) {
console.log('323');
$(event.target).hide();
});
Upvotes: 1