jQuery removeAttr() remove clickable behavior from links

Description

jQuery removeAttr() remove clickable behavior from links

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  ww w . j  a v  a2 s  .c o  m
    .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