-2

I am having a jQuery Script to find out the resolution of browser and then change its css.

if ((screen.width>=1024) && (screen.height>=768))
{
 alert('Screen size: 1024x768 or larger');
  $("link[rel=stylesheet]:not(:first)").attr({href : "detect1024.css"});
}
else
{
  alert('Screen size: less than 1024x768, 800x600 maybe?');
  $("link[rel=stylesheet]:not(:first)").attr({href : "detect800.css"});
}
});

can you please help me knowing its actual functioning?

what does :not(:first) mean ? Please explain.

Thanks.

6
  • 3
    Why aren't you using media queries? If it's because you need to support old browsers, there are workarounds.
    – thirtydot
    Jun 23, 2012 at 13:44
  • 4
    Have you looked at the API for :first and :not()? Jun 23, 2012 at 13:46
  • 2
    It means the same as :gt(0), using the greater-than selector
    – user1106925
    Jun 23, 2012 at 13:50
  • 1
    Don't give me that BS about googling a lot. I typed jquery :not(:first) into Google, verbatim, and before i even finished, the freaking autocomplete was giving me info. And jquery first not brought up docs on both selectors.
    – cHao
    Jun 23, 2012 at 13:55
  • 4
    Just think about what the words "not" and "first" mean. It's not that hard, given that these are words you use in daily writing.
    – BoltClock
    Jun 23, 2012 at 14:01

2 Answers 2

1

actually it means you select every link element with the attribute rel matching the word stylesheet but exclude the first of the found results :)

so if you have three elements in a container and try to select them using :not(:first) you will receive the second and the third one but exclude the first (!) one

not sure if it that is what you want... but if you have more then one link attribute in header and all except the first are set to that href you might (!) end up having the CSS requested / checked against server / cache several times

Media queries (thirtydot's comment) is also a good idea (comment +1)

0

Try using the an interactive console, such as the one in Chrome's inspector or Firebug in Firefox. Just type in $("link[rel=stylesheet]:not(:first)") and see if any elements are matched.

Edit: Thirtydot's comment about using media queries is a good one as well, and if you are going to have multiple stylesheet's this article may have some useful info.

2
  • Hi Cecchi, this is a great suggestion: "Try it", but I'm not sure it actually answers the question. While it would make a helpful comment, answers posted should answer the question since the goal of StackOverflow is to be a resource of knowledge for years to come. Additionally, when posting links, it's helpful to include a summary from the resource to highlight the most important points/main idea from the link. If the link were to ever break, the answer would be useless. Consider making an edit to include information from the link that addresses the question. Jun 23, 2012 at 18:42
  • [cont'd] - by including information from the link that would answer the question, you could then also justify leaving your comment in the answer as a helpful aside. Good luck! :) Jun 23, 2012 at 18:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.