Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

You can try following code to insert html.

$("#div1").html("<your HTML>");
<div id="div1"></div>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda