首页javascriptclassjQuery Style - 如何check如果元素有某个类

jQuery Style - 如何check如果元素有某个类

我们想知道如何check如果元素有某个类。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    if ( $('div').hasClass( 'test-class' ) ) {
        $( ".to-hide" ).css("display", "none");
    }
});
</script>
</head>
<body>
  <div class="test-class">This Stays</div>
  <div class="to-hide">THIS SHOULD BE HIDDEN</div>
</body>
</html>