0

Is it possible to check with JavaScript (jQuery) if there is a certain CSS file? And if there is that it loads a color array for jQuery plot?

Example:

  • I include a color CSS file (blue.css).
  • Javascript will check if there is a color CSS file (blue.css, red.css, grey.css).
  • There is blue.css in the page and the array colors for that CSS file ... is load for jQuery plot.

2 Answers 2

1

I would use the following approach.

  1. have a hidden <div id="colorIndicator" style="display:none"></div>
  2. have a css rule in every color.css with a corresponding color #colorIndicator { color: #ff0000; }
  3. On load make an ajax call to the server and get your colors

This could be the JavaScript using jQuery

$(function() {
    $.ajax( {
      method: 'POST',
      url: '/give/me/colors',
      data: { color: $('#colorIndicator').css('color'); },
      dataType: 'json',
      success: function(data) {
         // handle your json data
      }
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Sounds a lot like this q/a will help:

HOW TO check if an external (cross-domain) CSS file is loaded using Javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.