Search code examples
javascripthtmlcsshead

Does specific IE rules in <head> works for JS too?


I'm wondering if this code works or not:

<!--[if lt IE 8]>
      <script src="/assets/v3/application_ie.js" type="text/javascript"></script>
      <link href="/assets/v3/application_ie.css" media="all" rel="stylesheet" type="text/css" />
    <![endif]-->

I always saw these kind of rules with CSS only, so I'm wondering about javascript here.


Solution

  • Yes.

    In HTML, anything contained within <!-- ... --> is a comment. Anything contained within this comment block will be treated as a comment and not rendered as HTML (and ultimately not displayed on the page). Older versions of IE will parse through HTML comments looking for its square bracket notation and will render the HTML within if a match is made.

    Do note, however, that conditional comments like these are no longer supported in modern versions of IE.