Reputation: 36058
I want to learn jQuery. In my opinion jQuery just select the element you want and then do something on it. However the select manner is close to CSS selector. And I am not familiar CSS css selector since I always think it is rather unsystematic, I can not find any rules.
All I know about the CSS selector is the following:
#id
.class
So I wonder there is any rule when using CSS/jQuery selector?
UPDATE:
can you guys give me an explaination,I can not understand this:
In CSS 2.1, style is normally attached to an element based on its position in the document tree. This simple model is sufficient for many cases, but some common publishing scenarios may not be possible due to the structure of the document tree. For instance, in HTML 4 (see [HTML4]), no element refers to the first line of a paragraph, and therefore no simple CSS selector may refer to it.
Seems like it is the reason for "Pseudo-elements and pseudo-classes" imported,but what is the exactly meaning? How to understand "no element refers to the first line of a paragraph, and therefore no simple CSS selector may refer to it"?
Upvotes: 4
Views: 590
Reputation: 6764
It seems like you are confused between CSS and jQuery selectors. There is a difference between both in syntax and purpose as well. Take a look at these two selectors here. css selectors and jQuery selectors
With CSS selectors, you can just grab the static HTML elements and modify their styles. But technically you can not play with the HTML elements to change its behavior. In case of jQuery selectors, you can actually grab the static HTML elements and manipulate them. Which means you can change its behavior, you alter its position, you can change its text and also you can mathematically find them using nth-child selectors etc...
Upvotes: 0
Reputation: 21935
While I understand your question seems to be directed at CSS selectors in within the jQuery framework... But I must say jQuery does much more than making it easy to grab elements.
1) jQuery Tutorials
2) Plugin Authoring
3) Animation
4) jQuery UI
Also, it's important to understand jQuery and it's relationship with JavaScript. jQuery is a framework built on javascript. Thusly, I am a firm believer that a good JavaScript developer will make a great jQuery developer.
Upvotes: 0
Reputation: 630569
The jQuery API site has several tutorials just for selectors, take a look here - and it's part of the "getting started" tutorial here.
The rules are to use the correct selector for what you want to select...beyond that it depends on what you're trying to select; the first link above will help with which selectors do what, and when to use them.
Also to clarify, there are many selectors that aren't CSS selectors, they're jQuery specific additions, like the form selectors, basic filter selectors, visibility selectors, and content filter selectors.
Upvotes: 7