ID selector (“#id”)

Selects a single element with the given id attribute. For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient. When another selector is attached to the id selector, such as h2#pageTitle, jQuery performs an additional check before identifying the element as a match. Calling jQuery() (or $()) with an id selector as its argument will return a jQuery object containing a collection of either zero or one

.html()

Get the HTML contents of the first element in the set of matched elements. This method is not available on XML documents. In an HTML document, .html() can be used to get the contents of any element. If the selector expression matches more than one element, only the first match will have its HTML content returned. Consider this code: $( "div.demo-container" ).html(); In order for the following <div>'s content to be retrieved, it would have to be

:header selector

Selects all elements that are headers, like h1, h2, h3 and so on. Because :header is a jQuery extension and not part of the CSS specification, queries using :header cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :header to select elements, first select the elements using a pure CSS selector, then use .filter(":header"). jQuery( ":header"

.hasClass()

Determine whether any of the matched elements are assigned the given class. Elements may have more than one class assigned to them. In HTML, this is represented by separating the class names with a space: <div id="mydiv" class="foo bar"></div> The .hasClass() method will return true if the class is assigned to an element, even if other classes also are. For example, given the HTML above, the following will return true: $( "#mydiv" ).hasCla

Has attribute selector [name]

Selects elements that have the specified attribute, with any value. jQuery( "[attribute]" ) version added: 1.0 Examples: Bind a single click to divs with an id that adds the id to the div's text. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"&g

.get()

Retrieve one of the elements matched by the jQuery object. The .get() method grants access to the DOM nodes underlying each jQuery object. If the value of index is out of bounds â less than the negative number of elements or equal to or greater than the number of elements â it returns undefined. Consider a simple unordered list: <ul> <li id="foo">foo</li> <li id="bar">bar</li> </ul> With an index specified, .get

.focusout()

Bind an event handler to the "focusout" JavaScript event. This method is a shortcut for .on( "focusout", handler ) when passed arguments, and .trigger( "focusout" ) when no arguments are passed. The focusout event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the blur event in that it supports detecting the loss of focus on descendant elements (in other words, it supports event bubbling). This event wil

:has() selector

Selects elements which contain at least one element that matches the specified selector. The expression $( "div:has(p)" ) matches a <div> if a <p> exists anywhere among its descendants, not just as a direct child. Because :has() is a jQuery extension and not part of the CSS specification, queries using :has() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in mode

:gt() selector

Select all elements at an index greater than index within the matched set. index-related selectors The index-related selector expressions (including this "greater than" selector) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (.myclass) and four elements are returned,

.height()

Get the current computed height for the first element in the set of matched elements. The difference between .css( "height" ) and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation. figure 1 This method is also able to find the height of the wi