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

307
Views
If else conditional based on script type

So I'm working on a small snippet to determine when to inject HTML and I am having a hard time properly targeting the proper conditional.

So below, I will go into detail what I'm attempting to do:

I have the following <script> embed in the footer with an ID which changes the 'text/plain' to 'text/javascript' based on a plugin:

<script type="text/plain" id="google-maps-api-script" class="optanon-category-C0004" src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly"></script>

Inside the js, I am console logging the element ID using:

const script = $('#google-maps-api-script');
console.log(script);

This gives me a S.fn.init return with the [0] index always:
enter image description here

Now inside the attributes, I want to be able to do an If/else conditional based on the script type. So the attributes -> [0] or type -> nodeValue/value reveal that:
enter image description here

How can I properly make a conditional that says:

If (#google-maps-api-script type is 'text/plain') {
   // Do something
} else or if it's 'text/javascript')) {
   // Do something else
}

All help will be appreciated!

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

0

Use .attr('type') to get it:

if ($("#google-maps-api-script").attr("type") == "text/plain")) {
    // do something
} else {
    // do something else
}
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!