jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
$(elements)
$(elements)

为一个或多个DOM元素捆绑jQuery功能。

这个函数也可以接收XML文档和Window对象(虽然它们不是DOM元素)作为有效的参数。

返回值: jQuery

参数:
  • elements (Element|Array<Element>): 由jQuery对象封装的DOM元素
 
示例1:

与 $("div > p") 相同。

HTML 代码:

<p>one</p> <div><p>two</p></div> <p>three</p>

jQuery 代码:

$(document).find("div > p")

结果:

[ <p>two</p> ]

示例2:

把页面的背景颜色设置为黑色。

Sets the background color of the page to black.

jQuery 代码:

$(document.body).background( "black" );

示例3:

隐藏表单中的所有input元素。

Hides all the input elements within a form

jQuery 代码:

$( myForm.elements ).hide()

 
$( elems )

Wrap jQuery functionality around a single or multiple DOM Element(s).

This function also accepts XML Documents and Window objects as valid arguments (even though they are not DOM Elements).

Return value: jQuery
Parameters:

  • elems (Element|Array<Element>): DOM element(s) to be encapsulated by a jQuery object.
 

Example:

Sets the background color of the page to black.

$(document.body).css( "background", "black" );

Example:

Hides all the input elements within a form

$( myForm.elements ).hide()