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

94
Visualizações
How to add wrapAll jquery or php after tags with the same id

php

<?php foreach ($forlop as $value) : ?>
            <?php 
                $stringTitle = substr($value->getTitle(), 0, 1);
            ?>
            <?php if(is_numeric($stringTitle)){
                echo "<h3 id='other'>0-9</h3>";
            } else{
                echo "<h3 id=".strtolower($stringTitle).">".strtoupper($stringTitle)."</h3>";
            }?>
            <div class="item"><?php echo $value->getId(); ?></div>            
<?php endforeach; ?>
<h3 id="c">C</h3> 
<div class="item">1</div>
<div class="item">2</div>

<h3 id="d">D</h3> 
<div class="item">3</div>
<div class="item">4</div>

<h3 id="e">E</h3>
<div class="item">5</div>


js

$('[id]').each(function (i) {
    $('[id="' + this.id + '"]').slice(1).remove();
});

desired result

<h3 id="c">C</h3> 
<div class="items-add">
    <div class="item">1</div>
    <div class="item">2</div>
</div>
<h3 id="d">D</h3>
<div class="items-add"> 
    <div class="item">3</div>
    <div class="item">4</div>
</div>
<h3 id="e">E</h3>
<div class="items-add"> 
    <div class="item">5</div>
</div>

I want products with the same initials to be grouped together, I don't have an effective solution. I want to add a wrapper tag to the tags that have a class item in the loop using jquery is there any way I can do this . or have any other treatment let me know about your ideas. Thanks.

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

0

You can solve it in php like this:

<?php $oldTitle = ""; ?>
<?php foreach ($forlop as $value) : ?>
            <?php 
                $stringTitle = substr($value->getTitle(), 0, 1);
            ?>
            <?php if($oldTitle !== $stringTitle && $oldTitle !== ""){
                echo "</div>"; // close items add tag
            ?>
            <?php if(is_numeric($stringTitle)){
                echo "<h3 id='other'>0-9</h3>";
            } else{
                echo "<h3 id=".strtolower($stringTitle).">".strtoupper($stringTitle)."</h3>";
            }?>
            <?php if($oldTitle !== $stringTitle){
                echo "<div class='items-add'>";
                $oldTitle = $stringTitle;
            ?>
            <div class="item"><?php echo $value->getId(); ?></div>            
<?php endforeach; ?>
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