1
About checking the existence of an element on a Web page
Many people will write 1 if($ ("#tt")) { 2 //dosomething 3 }
In fact, it should be judged based on the length of the element obtained.
if ($ ("#tt"). Length>0) {//do something blog Park How to modify my tags }
Of course, it can also be converted into DOM objects to determine
if ($ ("tt") [0]) {//dosomethign}
2
About child element Filter selectors: Nth-child (index/even/odd/equation) and: EQ (index) should be used to note that the value of the former is calculated from 1, the latter starting from 0
The former selects the index child element or the odd and even element (Odd/even) under each parent element and: EQ (index) can only match one element.
Eg: nth-child (3n+1 ') can select an element with the index value under each parent element (3N+1) (remember that n is starting from 1 Oh ~)
3
When using: Input selector It is important to note that: input is a low-key God, he will not only choose <input>, and will also steal the magic of the choice <textarea><select><button>
4
The $ ("#form: Input") we used to count the number of elements in the form. length;
Very easy feet have wood, but a lot of people will subconsciously write $ ("#form1 input"). length~
I can't help but say it. descendant selectors and filter selectors it's easy to get the wrong twins, too.
var $hd =$ ('. Text:hidde '); // Note that there is a space after the text, and others choose the element that is class "text" in the hidden element filter selector (there must be a space to filter open bar ~)var $gl =$ ('. Text:hidden ') // Well, this is the selection of the Hidden class "text" element, the authentic descendant selector
5
Finally write your own discovery ~ that is, compared with if else, perhaps we can use the toggle () method to alternate a set of actions
eg
Togglebtn.click (function () { Span style= "color: #0000ff;" >if ($category. Is (": Visible" // hide some elements else // display some elements
$toggleBtn. Toggle (function() { // light a bar} funcrtion () { // or is it good to hold the lute half covered? }) // two function is OK
jquery selector Easy to overlook the big problem of small knowledge