Venki web
Venki web

Reputation: 85

Disable function (existing) if class name exists

Want to disable function if class name exists for particular container. Used below code.

if($("testElement1").hasClass("Content")){
   !testFunction();
}
else{

}

Want to add inside (Existing code)

$(window).on('scroll', function(){
  testFunction();
}

Thanks

Upvotes: 1

Views: 112

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337590

If I've understood what you're trying to achieve, you just need to invert the logic in the if condition:

$(window).on('scroll', function() {
    // if test element *does not* have the class 'Content'
    if (!$("testElement1").hasClass("Content")) 
        testFunction();
});

Upvotes: 1

Related Questions