Im able to get id, src, style or whatever with:
$(document).click(function (e) {
console.log('id :' + e.target.id);
});
But I want to get the class, why isnt that possible?
Im able to get id, src, style or whatever with:
$(document).click(function (e) {
console.log('id :' + e.target.id);
});
But I want to get the class, why isnt that possible?
$(document).click(function (e) {
console.log('class :' + e.target.className);
});
You have few options
call:
.attr('class');
call:
target.className
second will return all classes so if it is main content
it will give you string with them it is easier to use
.hasClass("class-name")
eg.
target.hasClass(".hidden")
returns true or false if element hass class or not. Most useful and reliable. Just check if it has your class of choice!
If you are using jQuery for the click event why not use it to get the class attribute
$(document).click(function () {
console.log('class :' + $(this).attr("class"));
});