Reputation: 17522
I am working on a small project.
I wish to add an anchor tag <a>
inside another element using the css content attribute and the :after pseudo.
e.g.
.classname:after { content: '<a>hello</a>'; }
// this will print "<a>hello</a>"
What I need it to do is make it have a working anchor tag, pointing to a given href
.
I know you can use something like this content: attr(title);
so it will use .classname
title
attribute as a text, I don't know if this is even possible but, it would be cool if it was.
Upvotes: 1
Views: 703
Reputation: 2985
You cant im afraid. You have to use javascript :(
A quick example of putting a link into a p with the id of myP tho... and a variable for a url (which could be obtained from any value really)...
var myUrl = "http://www.glcreations.co.uk";
document.getElementById("myP").innerHTML = "<a href='" + myUrl + "'>A link for you to click on</a>";
Upvotes: 1
Reputation: 723598
You can't use the CSS :before
and :after
pseudo-elements to insert HTML elements. To add HTML elements you need to use JavaScript.
Upvotes: 2