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.
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Maanstraat
  • 1,241
  • 7
  • 34
  • 63

2 Answers2

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
      }
    });
});
DanielB
  • 19,910
  • 2
  • 44
  • 50
0

Sounds a lot like this q/a will help:

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

Community
  • 1
  • 1
Sam Huggill
  • 3,106
  • 3
  • 29
  • 34