user34537
user34537

Reputation:

css { content: "text"}, how do I add tags?

I wrote some dummy css. Instead of a tag I got escaped characters. How can I add a div tag instead?

.HeaderName:after{
content: "<div class=\"Name2\">text</div>";
}

.Name2 {
color: red;
}

Upvotes: 33

Views: 84141

Answers (3)

Matteo Mosca
Matteo Mosca

Reputation: 7458

The content declaration cannot add tags to the page (tags are structural); additionally, CSS is meant for presentation changes, not structural content changes.

Consider using jQuery, instead, such as:

$(".HeaderName").after("your html here");

Upvotes: 45

Omiod
Omiod

Reputation: 11653

If you need that extra tag only to make the added text red, just do this:

.HeaderName:after{
    content: "text";
    color:red;
}

Tested on Chrome.

Upvotes: 14

Dominic Cooney
Dominic Cooney

Reputation: 6555

You can't insert tags using content: in CSS. Here is the relevant part of the spec; see the 'content' property in the CSS 2.1 spec.

Upvotes: 12

Related Questions