Kaigai Blog living abroad in my twenties

【My Study Load】JQUERY CODING

JavaScript Programming

JQUERY CODING

ready() Method

Use ready() to make a function available after the document is loaded:

$(document).ready(function(){
  $("button").click(function(){
    $("p").slideToggle();
  });
});

toggleClass() Method

This method checks each element for the specified class names. The class names are added if missing, and removed if already set – This creates a toggle effect.

$("button").click(function(){
  $("p").toggleClass("main");
});

Navigation Tab which will close when the user click somewhere else and open it when they click the button

$(document).ready(function(){	
    $(document).on('click',function(e){
        if($(e.target).closest('#notifi-logo-btn').length) {
            $('.notifi').toggleClass('on');
        }
        else {
            $('.notifi').removeClass('on');
        }
    });
});