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

105
Views
Jquery insert element in middle of siblings?

I have the following html

<ul class ="paragraphs">
  <li class="paragraph" element="1">1</li>
  <li class="paragraph" element="2">2</li>
  <li class="paragraph" element="3">3</li>
  <li class="paragraph middle" element="4">4</li>
  <li class="paragraph" element="5">5</li>
  <li class="paragraph" element="6">6</li>
  <li class="paragraph" element="7">7</li>
</ul>

I have a variable which is a random element (element="1" to element="7"), I am trying to position that element in middle, but keep other elements in order. So if the element was 2, the order would be 1342567, if the element was 7 the order is 1237456.

I start by removing the middle class

$(".paragraphs middle").removeClass("middle");

I then add .middle to the given element

$(".paragraphs .paragraph[ element=' + Element + ']").addClass("middle");

What I am trying to do now is add the .paragraph.middle in to the middle of the children? One way I was thinking is to check if the element is between 1-4 if so then insert after 4, If the element is between 4-7 then insert before the middle. But wondering if this is the best way, or if there is anything simpler?

Thanks

about 4 years ago · Juan Pablo Isaza
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!