SPQRInc
SPQRInc

Reputation: 198

Add HTML content after link with specific class

I would like to add some HTML after a link that has a specific class.

Well - this does not work:

a.mylinkclass:after { 
    content: "<div class='uk-badge'>Test</div>";
    color: green;
}

content does not allow HTML. So what other possibilities do I have to add HTML to a link with a specific tag?

Upvotes: 0

Views: 39

Answers (2)

DisplayName
DisplayName

Reputation: 795

You could use JavaScript, instead of CSS, to add the HTML after the link.

For example, you could use JQuery to do it: (as i see your question is tagged with)

$("a.mylinkclass").after("<div class='uk-badge'>Test</div>");

Upvotes: 1

The Alpha
The Alpha

Reputation: 146269

You may try something like this (using jQuery)

$("<div class='uk-badge'>Test</div>").insertAfter('a.mylinkclass');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href='' class='mylinkclass'>mylinkclass 1</a>
<a href='' class='myotherclass'>myotherclass</a>
<a href='' class='mylinkclass'>mylinkclass 2</a>
<a href='' class='myotherclass'>myotherclass</a>

Upvotes: 1

Related Questions