JQuery (expression, [context]), $ (jQuery) parameter problem, contextjquery

Source: Internet
Author: User

JQuery (expression, [context]), $ (jQuery) parameter problem, contextjquery
JQuery (expression,[Context]) Return Value: jQuery Overview

This function receives a string containing the CSS selector and uses this string to match a group of elements.

JQuery's core functions are implemented through this function. Everything in jQuery is based on this function, or is using this function in some way. The most basic usage of this function is to pass an expression (usually composed of CSS selectors) to it, and then find all matching elements based on this expression.

By default, if the context parameter is not specified, $ () searches for DOM elements in the current HTML document. If the context parameter is specified, such as a DOM element set or jQuery object, then it will be searched in this context. After jQuery 1.3.2, the returned element order is equivalent to the order in which the elements appear in the context.

Refer to the selector section in the document to obtain more information about the CSS syntax used for the expression parameter.

Parameters ExpressionString

String to be searched

Context(Optional)Element, jQuery

Used as the DOM Element Set, document, or jQuery object to be searched.

Example description:

Find all p elements, and these elements must be child elements of the div element.

HTML code:
<p>one</p> <div><p>two</p></div> <p>three</p>
JQuery code:
$("div > p");
Result:
[ <p>two</p> ]
Description:

In the first form of the document, find all the radio buttons (that is, the input element with the type value of radio ).

JQuery code:
$("input:radio", document.forms[0]);
Description:

Search for all div elements in an XML document returned by AJAX.

JQuery code:
$("div", xml.responseXML);

JQuery: $ (dom) What is context?

Context, return the original DOM node content that is passed to jQuery (), that is, the second parameter of jQuery. If not specified, context points to the current document

Example: $ ("div span", context );
Select the "div span" object from the context object. This is a usage of jQuery, that is, to find the object in the selected range.

$ (Dom) [0]. attributes is directly used to find the attributes under the First dom. Different from context, it specifies the search object.

Parameters of jquery event processing functions

If your code is the same as the above, it will certainly make an error, because JavaScript is case sensitive.

CLICK to write as click

<Script type = "text/javascript" >$ (function () {var str; var a = function (s) {str = s ;}; $ ("# "). click (function () {a ("X") ;}); $ ("# B "). click (function () {a ("Y") ;}); $ ("# check "). click (function () {alert (str) ;}); </script>
<P> <a href = "#" id = "A"> str = X </a> </p> <a href = "#" id =" B "> str = Y </a> </p> <a href =" # "id =" check "> check str </a> </p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.