一、jQuery選擇器
1、父元素(向上遍歷單一層級):parent()
2、祖先元素:parents(selector)
3、子元素(向下遍歷單一層級):children(selector)
4、後代元素:find(selector)
5、前一個兄弟元素:prev(selector)
6、之前所有兄弟元素:prevAll(selector)
7、後一個兄弟元素:next(selector)
8、之後所有兄弟元素:nextAll(selector)
9、所有兄弟元素:siblings(selector)
10、第一個:first()
11、最後一個:last()
12、第幾個(從 0 開始):eq(index)
13、排除元素(不需要某元素):not(selector)
二、僞選擇器
多選框選中的元素:$(':checked')
被禁用的元素$(':disabled)
取得到焦點的元素$(':focus)
第一個元素:$(':first')
最後一個元素:$(':last')
三、關係選擇器
空格:$('selector1 selector2') selector2是selector1的後代元素。
大於(>) :$('selector1>selector2') selector2是selector1的子元素(向下遍歷單一層級)。
逗號(,):$('selector1,selector2') selector2元素和selector1元素。並列選擇器。
四、其他常用函數
html()、val()、text()、append()、css()、
prop()、remove()、attr()、removeAttr、
addClass()、removeClass、toggleClass()、hasClass(class)、
遍歷:$(selector).each(function(){});
五、綁定事件(建議使用on不要使用bind)
綁定前先解綁不然可能導致重複綁定。
$(selector).off('click').on('click',function(){});