Javascript examples for jQuery Method and Property:attr
The following example demonstrates attr() with a callback function:
<!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>