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

84
Views
Jquery appendto div class selector

I have the following html

<div class="options">
  <div class="container">
    <div class="swatch-option selected"></div>
    <div class="info">Text</div>
  </div>
  <div class="container">
    <div class="swatch-option"></div>
    <div class="info">Text2</div>
  </div>
</div>

I try jquery to move "info" class, which has the previous class "swatch-option selected", at the end of the closing div class "options"

So my final html should be like

<div class="options">
  <div class="container">
    <div class="swatch-option selected"></div>
  </div>
  <div class="container">
    <div class="swatch-option"></div>
    <div class="info">Text2</div>
  </div>
  <div class="info">Text</div>
</div>

The jquery I tried is the following but it does not move the info class, which has the previous class swatch-option selected

<script>
    require([
    'jquery'
    ], function ($) {

    $(document).ready(function(){
     $('.selected.info').appendTo('.options');
    })
})
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$('.selected.info') means to search for an element that has both selected and info classes but they are siblings in your example.

You can use the adjacent sibling selector (+)

$(document).ready(function() {
  $('.selected + .info').appendTo('.options');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="options">
  <div class="container">
    <div class="swatch-option selected"></div>
    <div class="info">Text</div>
  </div>
  <div class="container">
    <div class="swatch-option"></div>
    <div class="info">Text2</div>
  </div>
</div>

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!