9630

by rwaldron

HTML

<div>
    <span></span>
    <!-- comment -->
    text
</div>

JavaScript

var $div = jQuery("div"), 
    $nodes = $div.contents();

console.log( 
   ( !$div.hasClass("undefined") && "PASS" ) || "FAIL", 
    " - Element DOES NOT have a class 'undefined'"
);

$div.addClass("undefined");

console.log( 
   ( $div.hasClass("undefined") && "PASS" ) || "FAIL",
    " - Element DOES have a class 'undefined'"
);

$div.removeClass("undefined");

console.log( 
   ( !$div.hasClass("undefined") && "PASS" ) || "FAIL",
    " - Element DOES NOT have a class 'undefined'"    
);


// jQuery will only classes to 
$nodes.each(function() {
   
    console.log( this.nodeName, this.nodeType ) 
});