Hammad Munir Hammad Munir - 2 months ago 5
Javascript Question

onclcik check if that element not hasClass()

i want to check on click that div or li any element not hasClass() then do something ..
i am trying to do like this...

$(document).on('click',function() {
if(!(this).hasClass("help-icons") && !(this).hasClass("help") && (this).hasClass("close")){
$(".help-icons").hide();
}else if((this).hasClass("help")){
$(".help-icons").show();
}else{
$(".help-icons").hide();
}
});


help me to solve this problem
thanks..

Answer

You forgot the $

$(document).on('click', function() {
  if(!$(this).hasClass("help-icons") && !$(this).hasClass("help") && $(this).hasClass("close")) {
    $(".help-icons").hide();
  } else if ( $(this).hasClass("help")) {
    $(".help-icons").show();
  } else {
    $(".help-icons").hide();
  }
});
Comments