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

140
Views
insertAdjacentElement limitation

I have a form it has three boxes also I have a btn under it for the add page.

I wrote it as follows, but I do not want to add more than two boxes:

let matForm = document.querySelector('.mat-form');

document.querySelector('.btn-add-area').addEventListener('click', () => {
        matForm.insertAdjacentElement("beforeend", `
        
        <div class="mat-box">
        <div class="mat-box-top">
            <a href="#" class="mat-btn" onclick="toggle()"><span>مواد</span></a>
            <a href="#" class="rounded-red"><i class="fa fa-multiply"></i></a>
        </div>
        <div class="mat-box-body">
            <input class="mat-equal sum3" type="text" name="sum_2" id="matvalue" placeholder="0">
            <div class="rounded-green"><i class="fa fa-equals"></i></div>
            <input class="mat-price price3" onchange="sumThree()" type="text" name="price_2"
                id="matvalue" placeholder="مقدار تومان">
            <div class="rounded-green"><i class="fa fa-plus"></i></div>
            <input class="mat-kg kg3" type="text" name="kg_2" id="matvalue" placeholder="KGمقدار">
            <div class="divide"><span>0%</span></div>
        </div>
        </div>
    
        `);
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about creating a counter to store how many times it added, and using the counter in an if condition to avoid adding box if count is 2

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!