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

197
Visualizações
Incremental counter right before each <br />

This should be easy, although I spent over 4 hours and nothing! I REALLY need to add a counter for <br /> tag, inside an specific DIV CLASS, to count lyric lines, and "echo" the corresponding number on each line right before the <br />. I understand that this can´t be done by css, like happens with <p>, because <br /> won´t allow before and after css conditionals. Will really appreciate the help.

Example:

Every time when I look in the mirror 1

All these lines on my face getting clearer 2

The past is gone 3

And it went by, like dusk to dawn 4

Isn't that the way? 5

Everybody's got their dues in life to pay 6

Yeah, I know nobody knows 7

Where it comes and where it goes 8

I know it's everybody's sin 9

You got to lose to know how to win 10

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

0

In PHP, you can use explode function to extract all new lines as below

$arr=explode(PHP_EOL, $lyrics);

foreach($arr as $index=>$ele){
echo $ele.$index+1.'<br>';
}

If you are getting another issues please fill free to comment.

about 4 years ago · Juan Pablo Isaza Relatório

0

If each line is a <p> you can do that to replace each <br>

var listElements = document.getElementsByTagName('br')

for(var i = 1; i <= listElements.length; i++){    
var line = listElements[i-1].parentElement.innerHTML

    listElements[i-1].parentElement.innerHTML = line.replace('<br', i+'<br')
}
<p>Every time when I look in the mirror <br /> </p>
    <p>All these lines on my face getting clearer <br /></p>
    <p>The past is gone <br /></p>
    <p>And it went by, like dusk to dawn <br /></p>
    <p>Isn't that the way? <br /></p>
    <p>Everybody's got their dues in life to pay <br /></p>
    <p>Yeah, I know nobody knows <br /></p>
    <p>Where it comes and where it goes <br /></p>
    <p>I know it's everybody's sin <br /></p>
    <p>You got to lose to know how to win <br /></p>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can simply count the numbers of any tags from simple javascript code.

let countbr = document.getElementsByClassName('count-br')[0].getElementsByTagName('br').length; 
console.log('Total </br> count on class count-br: ',countbr);
<div class="count-br">
  This page has 4 br
  </br>
test
</br>
test test test
</br>
</br>
</div>

<div class="donot-count-br">
  This section has 3 br
  </br>
test
</br>
test test test
</br>
</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