Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Can I inject br tag into string and make it work as an actual HTML tag?
const filterThroughItems = ((_siteNavItems) => {
        let siteNavItems = _siteNavItems;
        var n = _siteNavItems[0].links.length;
        const x = 0, y = 20;

        for (var i = 0; i < n; i++) {
          var cut = _siteNavItems[0].links[i].name;
          var sizeOfString = _siteNavItems[0].links[i].name.length;

          if (sizeOfString > 20) {
            cut = cut.slice(x, y) + '<br/>' + cut.slice(y);
            _siteNavItems[0].links[i].name = cut;
          } 
        }
        siteNavItems = _siteNavItems;
        return siteNavItems;
    })

so basically I filter through the Navigation bar and cut the string after first 20chars and want to enter a html <br/> (also tried \n and \r\n) inbetween it, so it splits the text into two lines.

<div name="A.01. Test string as<br/>ów test test test" class="ms-Nav-compositeLink is-expanded is-selected compositeLink-177">

<button class="ms-Nav-chevronButton chevronButton-195" aria-label="A.01. Test string as<br/>ów test test test" aria-expanded="true" tabindex="0"><i data-icon-name="ChevronDown" role="presentation" aria-hidden="true" class="ms-Nav-chevron chevronIcon-215"></i></button>

<a class="ms-Button ms-Button--action ms-Button--command ms-Nav-link link-210" href="/sites/WIN/SitePages/A1Test.aspx" title="A.01. Test string as<br/>ów test test test" data-is-focusable="true">

<div class="ms-Button-flexContainer flexContainer-200">

<div class="ms-Nav-linkText linkText-176">A.01. Test string as&lt;br/&gt;ów test test test</div></div></a></div> 

I tried to also work with the DOM but the actuall ClassName changes from linkText-176 incrementally.

My issue is that it DOES insert the br, but as a plain string and not as actual HTML. Any ideas how I can achieve that?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can set the inner HTML of an element:

document.getElementById("myElement").innerHTML = `<h1>Hello <br>Friend!</h1>`;
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try following code to insert html.

$("#div1").html("<your HTML>");
<div id="div1"></div>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda