jQuery hasClass() check class existence

Description

jQuery hasClass() check class existence

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Removing Clickable Behavior</title>
<style>
    .menu a{
        margin-left: 20px;
    }//from   w  ww.  j  ava 2s .c om
    .menu a.disabled{
        color: #666;
        text-decoration: none;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $(".menu a").each(function(){
        if($(this).hasClass("disabled")){
            $(this).removeAttr("href");
        }
    });
});
</script>
</head>
<body>
    <div class="menu">
        <a href="http://java2s.com">HTML</a>
        <a href="http://java2s.com">CSS</a>
        <a href="http://java2s.com">Bootstrap</a>
        <a href="http://java2s.com" class="disabled">CodeLab</a>
    </div>
</body>
</html>



PreviousNext

Related