Wednesday 2 May 2018

How to change anchor tag href attribute of a hyperlink using jQuery


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Set HREF for Anchor Tag</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('a[href^="http://"]').each(function () {
            var oUrl = $(this).attr("href"); // Get the current url
            var nUrl = oUrl.replace("http://", "https://"); // new url
            $(this).attr("href", nUrl); // Set herf new url
        });
    });
</script>
</head>
<body>
    <p><a href="http://www.google.com">Google</a></p>
    <p><a href="http://www.gmail.com">Gmail</a></p>
</body>
</html>

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...