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

163
Views
Div placed using JavaScript are not displayed in the correct place

I have a problem with inserting a specific element using JavaScript.

First of all, my website structure is as follows.

<div class="woocommerce-billing-fields__field-wrapper">
<p id="billing_email_field">..</p>
<p id="billing_country_field">..</p>
<p id="billing_first_name_field">..</p>
<p id="billing_postcode_find_field">..</p>
<p id="billing_address_1_field">....</p>
</div>

I want to add a Wrap element above the billing_address_1_field element.

So I put the Warp element using the code below.

<script>
    //빌링에 wrap 엘리멘트 추가
    const parent = document.querySelector('#woocommerce-billing-fields__field-wrapper');
    const billingField1 = document.querySelector('#billing_address_1_field');

    const newDiv = document.createElement('div');
    newDiv.setAttribute('id', 'wrap');
    newDiv.style.cssText = 'display:black;width:100%;margin:5px 0;';

   parent.insertBefore(newDiv, billingField1);
</script>

However, when using this code, the warp will be placed on top of the div element.

<div class="woocommerce-billing-fields__field-wrapper">
        <div class="wrap"></div>
        <p id="billing_email_field">..</p>
        <p id="billing_country_field">..</p>
        <p id="billing_first_name_field">..</p>
        <p id="billing_postcode_find_field">..</p>
        <p id="billing_address_1_field">....</p>
</div>

Can someone please tell me how i can solve this problem?

I'd like to use insertBefore instead of prepend due to compatibility issues with IE.

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

On your script please add a dot(.) instead of hash(#) :

const parent = document.querySelector('.woocommerce-billing-fields__field-wrapper');

hope it will help. Thanks

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!