There is a simple piece of code:

<h1>Каталог товаров</h1>. 

Before him you need to insert a link:

 <a href="мойсайт.ру">Главная</a> 

The problem is that it needs to be done only with the help of css . When using :before , the text is displayed, not the html tag. How to be in this case?

  • one
    Alas, but you do not. You can't do without javascript here ... - Seredniy
  • Do not do this with the help of css. Maybe I will correct, but you can not insert the html- code in the content . At least it was impossible before. It was possible to add css styles to the content, and that did not work in all browsers. - Moonvvell
  • The problem is that there is no access to the html code. If you can do it with JS - how to do it? - ArtemPetrov
  • Read the help on how the "content" property works and find out what you want the impossible - htmlcoder
  • If you want to display the html code using javascript, then as the easiest way, use document.write('<a href="мойсайт.ру">Главная</a>'); - htmlcoder

1 answer 1

On css there is no such possibility. Using js can be something like this:

 var section = document.querySelector("div.section"), link = document.createElement("a"), // создаём <a></a> linkText = document.createTextNode("Главаня"); // добавляем анкор "Главаня" link.appendChild(linkText); // <a>Главаня</a> link.href = "мойсайт.ру"; // <a href="мойсайт.ру">Главаня</a> section.insertBefore(link, section.firstChild); // Добавляем всё это дело в начало блока .section 
 <div class="section"> <h1>Каталог товаров</h1> </div> 

using jquery will be enough:

 $( '<a href="мойсайт.ру">Главаня</a>' ).insertBefore( "h1" );