$("div"). references all divs?
Looking at some code, I see this line: $("div").disableSelection();
What the...
In the CSS, there are no divs n开发者_C百科amed "div", so is the above line of code referencing all divs in the CSS?
In short, yes. In css, the name of a tag references all instances of that tag in your HTML. The same is true for the jQuery selector.
Yes, jquery's selection syntax is Tag:symbol:name where tag is any HTML tag, symbol is either .
for class or #
for id, and name is the value to match in class/id
So $("h1")
would select all <h1>
tags in the page, $("h1.foo")
would select all tags matching <h1 class="foo">
, and finally $(".bar")
would match all elements regardless of tag with class="bar"
jQuery does not "select elements from CSS". It selects them from the DOM. Very little in your CSS will ever change what jQuery finds in the DOM (save pseudo selectors like :visible
, etc.).
That code is using what jQuery calls an 'element selector' (docs), and is therefore selecting all DIVs in the DOM.
And as Felix Kling pointed out in the comments, CSS does have such a selector as well.
It references all divs in the current HTML markup.
精彩评论