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

90
Views
Activating alternate <script> tags

Suppose I have a web document with alternate content, that is, if some condition is met, it should display content A, and if the condition isn't met, it should display content B. That's easy to implement - I wrap each content with a <div> tag, setting its style to display:none, and have some JS code that changes one of them to displayed according to the condition.

But suppose content A and content B aren't just plain html. Each of them contains <script> tags. I want these scripts to be in effect only if the corresponding content is displayed, that is, if my condition is met, I want all the <script>s in content A to be in effect, and all the <script>s in content B to be ignored, and vice versa.

Actually there're two questions here. Firstly, i want the <script>s in (say) content A to be compiled (and run) only when I tell them so, that is, after I decide that my condition is true. Secondly, when the condition becomes false, I want all the functions defined in these scripts to be undefined, and instead of them, I need to compile and run all the scripts in content B (the condition may become true again later, and then false again, and so on).

How can I do it?

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!