javajavascriptjqueryhyperlinkcredits

Credit link not work according to the given my script


Well i am coding a script which will avoid editing of credits here is my total page code:

//start the script after loading the page
$(document).ready(function(){
//get the elements from page
var urlvalue1 = document.getElementById("#mycredit").href;


//correct link
if (urlvalue1 == "http://themedaddy.net" )
{window.location.replace("#");
}
//edited link
else{
window.location.replace("http://themedaddy.net");
}

But it is not working even i have added the following html code in the body section and linked the jquery script to it.

<a href="http://themedaddy444444.net" id="mycredit">ThemeDaddy</a>

According to the script it must need to get redirected as the link value is not satisfying.


Solution

  • Its working fine you have only mistakenly written #mycredit instead of mycredit while selecting the anchor tag.

    $(document).ready(function(){
    
            var urlvalue1 = document.getElementById("mycredit").href;
            if (urlvalue1 == "http://themedaddy.net" )
            {
                window.location.replace("#");
            }
            //edited link
            else{
            window.location.replace("http://themedaddy.net");
            }
    
        });
        </script>
        <a href="http://themedaddy444444.net" id="mycredit">ThemeDaddy</a>
    

    See this is working absolutely fine

    In selecting elements with getElementById we do not need to put # sign before Id :)