Return "True" on Empty jQuery Selector Array - Javascript jQuery

Javascript examples for jQuery:Array

Description

Return "True" on Empty jQuery Selector Array

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(function(){// w  w w .j av  a2s.  c om
$.extend($.expr[':'],{
    present: function(a) {
        return $(a).length;
    }
});
console.log($('#lnk').is(':present'));
console.log($('#notLnk').is(':present'));
    });

      </script> 
 </head> 
 <body> 
  <a id="lnk">Link</a>  
 </body>
</html>

Related Tutorials