Common methods of jquery

Time:2020-12-14

jQuery

EQ () and get ()

  • Get(): jQuery object to DOM object.

  • EQ (): jQuery object builds a new jQuery object.$(selector).eq( 0 )

Find element

  • Filter (selector) reduces the scope of matching and filters in the initial jQuery object collection$("p").filter(".selected, :first")

  • Find (selector) does not have the contents of the initial collection

  • JQuery () to return to a previous command set wrapper.

  • contents()

  • Parent (selector) finds the parent node. You can pass in expr for filtering, such as $(“span”). Parent() or $(“span”). Parent (“. Class”)

  • Parents (selector) is similar to. Parent (expr), but it looks for all ancestor elements, not only parent elements

  • Close (selector) gets the first ancestor element of the matching selector, starting from the current element up the DOM tree

  • Children (expr) returns all child nodes. This method only returns direct child nodes, not all child nodes

  • Prev() returns the previous sibling node, not all siblings

  • Prevlall() returns all previous siblings

  • Next () returns the next sibling node, not all siblings

  • Nextall() returns all subsequent siblings

  • Siblings() returns the sibling node

Styles & Properties

  • Addclass() & removeclass() add & remove class name

  • If the toggleclass() class name does not exist, the specified class name is added; if the element already has the specified class name, the specified class name is removed from the element.

  • CSS (name, value) specifies the CSS style property

  • Attrib() returns the value of attributes

  • Prop() returns the value of property

event

  • Event property

    • event.pageX The mouse position relative to the left edge of the document.

    • event.pageY The mouse position relative to the top edge of the document.

    • event.preventDefault () the default action to block events.

    • event.target The DOM element that triggers the event.

    • event.type Describes the type of event.

  • Bind (eventName, CB) can customize the event

  • Unbind() removes an added event handler from the matching element

  • On (event, childselector, data, function, map) adds event handlers for current and future elements (such as new elements created by scripts)

  • Off () method

  • One() adds an event that runs only once and then removes it

  • Trigger (eventName, Param1, param2,…) param optional, additional parameters passed to the event handler, which are particularly useful for custom events.

Insert element

  • Insertafter() & after(): inserts the element from behind outside the existing element

  • Insertbefore() & before(): inserts the element from the front outside the existing element

  • Appendto() & append(): inserts the element from behind inside the existing element

  • Prependto() & prepend(): inserts the element from the front inside an existing element

ergodic

  • Each() each returns the original array and does not create a new array.

  • Map () and the map method returns a new array.