Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE HTML>
<html>
  
  <head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <title>Stuff</title>
    <meta charset="UTF-8">
    <script>
      //the return values are arbitrary
      function getAttrStat(elem, attr) {
        var attrValue = null,
          attrStatus = (attrValue = elem.attr(attr)) || 0;
        if (attrStatus === 0) {
          if (attrValue === "") {
            //attr is empty
            console.log(elem.selector + " '" + attr + "' is empty.");
            $('body').append('<br>');
            $('body').append(elem.selector + " '" + attr + "' is empty.");
            return 1;
          } else if (typeof attrValue == "undefined")
          //attr is undefined
            console.log(elem.selector + " '" + attr + "' is undefined.");
          $('body').append('<br>');
          $('body').append(elem.selector + " '" + attr + "' is undefined.");
          return 0;
        } else {
          //attr has a value
          console.log(elem.selector + " '" + attr + "' has a value: " + attrValue);
          $('body').append('<br>');
          $('body').append(elem.selector + " '" + attr + "' has a value: " + attrValue);
          return 2;
        }
      }
      $(document).ready(function () {
        var statusCode = getAttrStat($('#a-id'), "class");
        console.log(statusCode);
        var statusCode = getAttrStat($('#b-id'), "class");
        console.log(statusCode);
        var statusCode = getAttrStat($('#c-id'), "class");
        console.log(statusCode);
      });
    </script>
  </head>
  
  <body>
    <div id="a-id"></div>
    <div class="" id="b-id"></div>
    <div class="c-class" id="c-id"></div>
  </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers