Is it possible to make an html tag a link to another page on website using either css or javascript? I am trying to edit a wordpress site but it only gives options for custom css and javascipt.
Thanks
Is it possible to make an html tag a link to another page on website using either css or javascript? I am trying to edit a wordpress site but it only gives options for custom css and javascipt.
Thanks
Try this javascript:
document.getElementById("link").onclick = function() {
window.location.href = "http://stackoverflow.com";
}
<p id="link">Go to Stack Overflow</p>
and with CSS to make it look like an anchor tag:
#link {
color: blue;
text-decoration: underline;
}
You can add html tags using javascript in a couple ways.
The most straightforward way (though it can be dangerous if you put malicious html in), is to use
someNode.innerHTML = <some markup>
, or if you have jquery: obj.html('');
Knowing that, you can use the html link tag (the <a>
) to add a link.
so if I want to put in link to google in my header i'd first select my header:
var header = document.getElementById('header');
Then I'd add the a tag to the header:
header.innerHTML += '<a href="www.google.com">Google</a>
;
This is answered at onclick="location.href='link.html'" does not load page in Safari.
onclick="javascript:location.href='http://www.example.com/'"