Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!