1. #id
2. Element
3. .class
4. *
分別說明如下:
1. #id 是唯一的, 利用 id 來選擇, 這個是最獨立的而指作法, 例如:
代碼: 選擇全部
$("#mydiv") 是選取 id="mydiv" 的 element
代碼: 選擇全部
$("div") 是選取所有 div 的 html tag element
代碼: 選擇全部
$(".myclass") 是選取使用 .myclass 的 element
代碼: 選擇全部
$("*")
1. tag.class
2. parent>child
3. ancestor descendant
4. prev+next
5. prev~siblings
說明整理如下:
1. tag.class 的語法, 例如:
代碼: 選擇全部
$("p.myclass") 是選取 html tag 為 p 的, 並 class 為 .myclass 的 element
代碼: 選擇全部
$("#div1 > *") 是選取 id="div1" 內的所有子層 element
代碼: 選擇全部
$("#div1 div") 是選取 id="div1" 內的所有 html tag 為 div 的 element
代碼: 選擇全部
$("#div1+div") 是選取 id="div1" 的下一個 html tag 為 div 的 element
代碼: 選擇全部
$("#div1~div") 是選取 id="div1" 之後的所有同階層的 html tag 為 div 的 element
再來是多重選取的部分, 在 $() 內放置多重要選取的內容, 並利用逗號(,)隔開, 例如:
代碼: 選擇全部
$("#div1, #div2, .class1")
這些是 selector 的使用方式, 給大家參考.