Note:$ ("#tt") gets the object forever, without this element on the instant page. Therefore, when you want to use jquery to check whether an element exists on a Web page, you cannot use the following code :
The IF ($ ("#tt")) {} should be judged based on the length of the element obtained, the code is as follows: if ($ ("#tt"). length>0) {} or Convert DOM object to determine the code as follows: if ($ ("tt") [0]) {}
Basic Selector
#id ID Selector $ ("#test") select an element with ID test
. class Selector $ (". Test") to select an element of class test
Element element Selector $ ("P") selects all <p> elements
* Match all elements $ ("*") Select all elements
Selector1,slector2,...., Selectorn Match to each element after merging returns $ ("Div,span,p.myclass") Select All <div>,<span> And a set of elements with a <p> tag of class MyClass
eg
$ ("#one"). CSS ("Background", "#000000"),//jquerydocument.getelementbyid ("one"). Style.color = "Red";//dom
Hierarchy Selector
$ ("div span") Select all the span elements in the DIV
$ ("Div>span") Select the span sub-element under Div
$ (". One+div") Select the next div sibling element of class one
$ ("#two ~div") selects all div sibling elements that follow the element with ID of.
Note: The following two selectors can be replaced in a simpler way
$ (". One"). Next ("div");
$ ("#two"). Nextall ("div");
The top two methods are to select the behind DIV element
$ ("#two"). Siblings ("div"); get all of the sibling div before and after
jquery Selector-base selector, hierarchy Selector