jQuery essential tips


  • Check existence of an attribute :if ($('#id').attr('attributo') !== undefined) {
    // attribute exists
    }
    NOTE: id attribute is never undefined, but equal to ""

  • Check existence of an element :if ($('#id').length > 0) {
    // element exists
    }

  • Show/Hide image ajax loading :html :

    javascript:
    $(document).ready(function(){
    $('#loadingimg').ajaxStart(function() {
    $(this).show();
    }).ajaxStop(function() {
    $(this).hide();
    });
    }

Commenti