jQuery <a> remove href attribute

Description

jQuery <a> remove href attribute

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Removing an Attribute from the Elements in jQuery</title>
<style>
  a{/*from  w w  w.ja va 2 s. c o m*/
        font-size: 18px;
    margin-right: 20px;
  }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    // Removes the hyperlink's href attribute on button click
    $("button").click(function(){
        $("a").removeAttr("href");
    });
});
</script>
</head>
<body>
    <div class="container">
        <p>
      <a href="http://java2s.com">Home</a>
      <a href="http://java2s.com">About</a>
      <a href="http://java2s.com">Contact</a>
    </p>
        <button type="button">Remove Attribute</button>
    </div>
</body>
</html>



PreviousNext

Related