A Callback Function for attr() - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:attr

Introduction

The following example demonstrates attr() with a callback function:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#w3s").attr("href", function(i, origValue){
            return origValue + "/jquery";
        });//from  w w w .  ja  v  a  2s .  co m
    });
});
</script>
</head>
<body>

<p><a href="http://java2s.com" id="myId">java2s.com</a></p>

<button>Change href Value</button>

</body>
</html>

Related Tutorials