How does jQuery get elements
JQuery uses a method called $(selector) to get action elements on a page. Selector takes strings or arrays of elements
Select expressions using CSS selectors or jquery-specific expressions:
//CSS selector $(document) // select the entire document object $('#myId') // select the web element $('div. MyClass ') // select the div element whose class is myClass $('input[name=first]') $('input[name=first]') $('a:first') $('tr:odd' $('#myForm :input') $('div:visible') $('div:gt(2)') Except for the first three $('div:animated') // select the div element that is currently animatedCopy the code
How is jQuery chained
One of the design ideas of JQuery is that it uses an idea called chain programming. Once you take an element, you can perform a series of operations on it, and all of these operations can be connected, like a chain of execution. Such as $(‘ div ‘). The find (‘ a ‘). Eq. (2) the HTML () ‘go’
How does jQuery create elements
JQuery has wrapped the creation element, we can just pass in the HTML string, jQuery will automatically create the node for us. Such as:
$(`
<div>
<span class="red">
this is new node
</div>
</div>`)
Copy the code
How does jQuery move elements
JQuery provides four teams of methods for manipulating the position of elements in a web page
.insertafter () 'and.after() : outside the existing element, insert elements.insertbefore () and.append() : outside the existing element, insert elements.appendto () and.append() from the front: Inside the existing element, insert elements from behind. PrependTo () and. Prepend () : Inside the existing element, insert elements from the frontCopy the code
How does jQuery modify an element’s attributes
JQuery provides several methods to modify the attributes of an element:
/ / tag attributes to add and delete $(' # div.) attr (' class ') / / $(' # div.) attr (' class ', 'red') / / increase and change; If there is a modification, If you don't have is add $(' # div.) removeAttr (' class ') / / delete / / the class add $(' # div.) addClass (' red ') / / to add $(' # div). RemoveClass (' red ') / / delete $('input[name="username"]').val()Copy the code
reference
- JQuery design and implementation