bradly
bradly

Reputation: 25

Why The Anchor Is not Working In this Script?

I am a Template developer,

i created one script for footer credit link, so that the user cannot remove the footer link,

However, i am bit confuse why the anchor is not working ?

here is the script.

<script>
window.onload = function() {
    var e = document.getElementById("credit");            
    e.setAttribute("href", "http://www.example.com/");
    e.setAttribute("ref", "dofollow");
    e.setAttribute("title", "Free Templates");
    e.innerHTML = "Example"

}
</script>

As you see the above script, i included that in my template and also i add the credit div in footer area like this:

<div id="credit"></div>

Now when i open my template, It seems as plain texts.

Problem: Why the Example seems as plain texts it is not anchor. how to make it clickable so that it should go to example.com if click.

Fiddle: https://jsfiddle.net/copyblogger/dkt2jdxt/5/

Note: please share full coding with fiddle example.

Upvotes: 0

Views: 77

Answers (2)

Taylor Glaeser
Taylor Glaeser

Reputation: 1313

The href attribute is only supported on the following elements: <a>, <area>, <base>, <link>.

You could wrap the <div> in an <a> element and then the entire div would be clickable.

Upvotes: 1

xtrinch
xtrinch

Reputation: 2281

Try this:

<a id="credit"></a>

You've been setting attributes that a div tag does not have, but an a tag does.

Upvotes: 2

Related Questions