{"title":"CSS4 Selectors","html_url":"https://deallocatedobjects.com/posts/css4-selectors","source_url":"http://dstorey.tumblr.com/post/10865123182/selectors4","markdown_content":"Looks like the [CSS Working Group](http://www.w3.org/Style/CSS/members) has published their [first working draft](http://www.w3.org/News/2011#entry-9219) of how they'd like CSS4 selectors to work.\r\n\r\nHere are some of the highlights:\r\n\r\n``` javascript\r\n    var el = document.querySelector(\"#foo\"); // returns first element with ID of foo\r\n    var bar = document.querySelector(\":scope > p\", el); // returns equivalent of \"#foo > p\"\r\n```\r\n\r\n``` css\r\nli a:matches(:link, :hover, :visited)\r\n```\r\n\r\n``` css\r\na:local-link /* Matches anything that links to the current page */\r\na:local-link(0) /* Matches any link that is the same domain */\r\n```\r\n\r\nThere's tons more and [David Storey](http://about.me/dstorey) does a great job of explaining stuff in [his blog post](http://dstorey.tumblr.com/post/10865123182/selectors4).\r\n","html_content":"<p>Looks like the <a href=\"http://www.w3.org/Style/CSS/members\">CSS Working Group</a> has published their <a href=\"http://www.w3.org/News/2011#entry-9219\">first working draft</a> of how they’d like CSS4 selectors to work.</p>\n\n<p>Here are some of the highlights:</p>\n<figure class=\"code\" data-lang=\"javascript\"><figcaption><span class=\"lang\">JavaScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#F97583\">    var</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> el </span><span style=\"--shiki-light:#24292E;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> document.querySelector(\"#foo\"); // returns first element with ID of foo</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#B392F0\">    var</span><span style=\"--shiki-light:#24292E;--shiki-dark:#B392F0\"> bar</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> = document.</span><span style=\"--shiki-light:#24292E;--shiki-dark:#B392F0\">querySelector</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#24292E;--shiki-dark:#9ECBFF\">\":scope > p\", el);</span><span style=\"--shiki-light:#24292E;--shiki-dark:#9ECBFF\"> // returns equivalent of \"#foo > p\"</span></span></code></pre></figure><figure class=\"code\" data-lang=\"css\"><figcaption><span class=\"lang\">CSS</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">li</span><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\"> a</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">:matches</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">:link</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">:hover</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">:visited</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)</span></span></code></pre></figure><figure class=\"code\" data-lang=\"css\"><figcaption><span class=\"lang\">CSS</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">a</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:</span><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">local-link</span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\"> /* Matches anything that links to the current page */</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">a</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:local-link(0) </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">/* Matches any link that is the same domain */</span></span></code></pre></figure>\n<p>There’s tons more and <a href=\"http://about.me/dstorey\">David Storey</a> does a great job of explaining stuff in <a href=\"http://dstorey.tumblr.com/post/10865123182/selectors4\">his blog post</a>.</p>","created_at":"2013-11-16T05:10:25.641Z","updated_at":"2013-11-16T05:10:25.641Z"}