Is it possible to check which element was clicked with event target?
e.on('click', function(){
if(!$(e.target) == 'input'){
//do something
}
});
I've tried the following construction, but it seems not to be working, same as:
e.on('click', function(){
if(!$(e.target).is('input')){
//do something
}
});
I just don't know is it possible for event target to check something like that.
You have to specify where is the element you click. Let's say we have this html:
html
<div></div>
jQuery
$("body").on("click", function(e) {
if($(e.target).is("input")) {
console.log(e.target);
}
});
fiddle
Pure JS
document.onclick = function(evt) {
var evt=window.event || evt; // window.event for IE
if (!evt.target) evt.target=evt.srcElement; // extend target property for IE
alert(evt.target); // target is clicked
}
fiddle
You should pass event
like e . to check the clicked element has input or not use is selector in jquery
$("selector").on('click', function(e){
if(!$(e.target).is('input')){
//do something
}
});
is() selector in jquery
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With