0

I want to use CSS instead of JavaScript to insert a HTML tag. But the tag gets interpreted as normal text rather than html code.

#br:after {
    content: "\003c br\003e"
}


<span>My </span>
<span> Name </span>
<span id="br"> is </span>
<span> XYZ</span>

What is getting displayed is:

enter image description here

Engineer
  • 161
  • 1
  • 5
  • 16
  • Take a look: http://stackoverflow.com/questions/24658337/css-content-to-add-html-tags – chf Jul 09 '14 at 15:57
  • 1
    @chf you linked to this page. (did you mean [this link?](http://stackoverflow.com/questions/7363766/how-to-insert-a-line-break-before-an-element-using-css)) css can't insert html tags, it's for decoration only. You can use effects to simulate a br though, check out the question (same idea with `:after` as `:before` – serakfalcon Jul 09 '14 at 16:00
  • Ops http://stackoverflow.com/questions/4505093/css-content-property-is-it-possible-to-insert-html-instead-of-text – chf Jul 09 '14 at 16:04

2 Answers2

2

A similar effect can be achieved:

#br:after {
  content: "";
  display: block;
}

http://jsfiddle.net/2j4JD/

Rowan Gray
  • 186
  • 5
1

HTML code cannot be inserted, the tags show up as '<tag>'.

user3809590
  • 155
  • 1
  • 2
  • 13