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

245
Views
JS should only show if element is available else not

I have following code

  if (K.API.Core.runWhenElementPresent('.has-flag', function () {
        var KamTestTemplate= '<div id="KamNotice"<span>text</span></div>';
        document.querySelector('#product-transaction-area').insertAdjacentHTML('afterbegin', KamNoticeTemplate)
    }));
    
    else if (K.API.Core.runWhenElementPresent('.product-media', function () {
        var KamTestTemplate= '<div id="KamNotice"<span>text</span></div>';
        document.querySelector('.product-media').insertAdjacentHTML('afterbegin', KamNoticeTemplate)
}));
    

I want that if the first div has-flag, the content should be shown in the transaction-area, and if the div has product-media, it should be shown within the product-media content box, but something is wrong with my code i get the content in both boxes, not in one.

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!