Can someone explain this Jquery

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

I'm not getting this part: $("link[rel=stylesheet]:not(:first)").attr

Answers


It selects all link tags, that have an attribute named rel, whose value is stylesheet, and that is not the first one of the tags. For example, if you had:

<link rel="icon" />
<link rel="stylesheet" href="style2.css" />
<link rel="stylesheet" href="style3.css" />
<link rel="stylesheet" href="style4.css" />

The selector would pick the last two link tags. Why? Because it excludes the first one, since the value of the rel attribute is not stylesheet, but icon; and excludes the second one, because it's the first of all the links that have the attribute rel="stylesheet", and not(:first) filters this one out.


Need Your Help

Absolute CSS positioning with a top margin

javascript html css angularjs

I have a sidebar with some text and a footer inside it (which sticks to the bottom of the sidebar). When I resize (reduce) the window's height to e.g. half, the footer goes on top of the other text...

How to run a query for year to date based on end date

sql datetime sql-server-2000

I have a query that runs based on the "end date" picked. Essentially the user picks the end date, and the query will run the report for the entire YTD based on the end date. So for example if I s...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.