How to change anchor element URL dynamically?

The HTML <a> element (or anchor element) creates a hyperlink to other web pages, files, locations within the same page, email addresses, or any other URL.

Change anchor element (<a>) href url dynamically by using jquery.

<script>
$(document).ready(function()
{
$("p").text("Anchor element url = "+$("a").attr("href"));
    $("button").click(function()
    {
        $("a").attr("href","http://www.webspeckle.com");
        $("p").text("Anchor element url = "+$("a").attr("href"));
    });
});
</script>
Final code and demo is here


Demo

No comments:

Post a Comment