78
Methods
In addition to the methods listed here, Input elements also implement all of the methods
defined by
Element
and
FormControl
. The methods marked with an asterisk in this list are
newly defined by HTML5 and are not yet, at the time of this writing, widely implemented.
void select()
This method selects all the text displayed by this Input element. In most browsers, this means
that the text is highlighted and that new text entered by the user replaces the highlighted text
instead of being appended to it.
void setSelectionRange(unsigned long start, unsigned long end)
This method selects text displayed in this Input element, starting with the character at position
start
and continuing up to (but not including) the character at
end
.
void stepDown([long n])*
For elements that support the
step
property, decrease the current value by
n
steps.
void stepUp([long n])*
For elements that support the
step
property, increase the current value by
n
steps.
jQuery
jQuery 1.4
the jQuery library
Description
This is a quick reference for the jQuery library. See Chapter 19 for complete details on the
library and for examples of its use. This reference page is organized and formatted somewhat
differently than the other pages in this reference section. It uses the following conventions in
the method signatures. Arguments named
sel
are jQuery selectors. Arguments named
idx
are
integer indexes. Arguments named
elt
or
elts
are document elements or array-like objects
of document elements. Arguments named
f
are callback functions and nested parentheses are
used to indicate the arguments that jQuery will pass to the function you supply. Square
brackets indicate optional arguments. If an optional argument is followed by an equals sign
and a value, that value will be used when the argument is omitted. The return value of a
function or a method follows the close parenthesis and a colon. Methods with no return value
specified return the jQuery object on which they are invoked.
jQuery Factory Function
The
jQuery
function is a namespace for a variety of utility functions, but it is also the factory
function for creating jQuery objects.
jQuery()
can be invoked in all of the ways shown below,
but it always returns a jQuery object that represents a collection of document elements (or
the Document object itself). The symbol
$
is an alias for
jQuery
, and you can use
$()
instead
of
jQuery()
in each of the forms following:
jQuery
Client-Side JavaScript Reference | 945
Client-Side
JavaScript
Reference
How to C#: Basic SDK Concept of XDoc.PDF for .NET XDoc.PDF for .NET allows C# developers to edit hyperlink of PDF document, including editing PDF url links and quick navigation link in bookmark/outline.
adding links to pdf in preview; add hyperlink to pdf acrobat VB.NET PDF: Basic SDK Concept of XDoc.PDF XDoc.PDF for .NET allows VB.NET developers to edit hyperlink of PDF document, including editing PDF url links and quick navigation link in bookmark/outline.
add url pdf; add hyperlinks to pdf
57
jQuery(sel [, context=document])
Returns a new jQuery object that represents the document elements that are descendants
of
context
and match the selector string
sel
.
jQuery(elts)
Returns a new jQuery object that represents the specified elements.
elts
may be a single
document element or an array or array-like object (such as a NodeList or another jQuery
object) of document elements.
jQuery(html, [props])
Parses
html
as a string of HTML-formatted text and returns a new jQuery object that
contains the one or more top-level elements in the string. If
html
describes a single HTML
tag,
props
may be an object that specifies HTML attributes and event handlers for the
newly created element.
jQuery(f)
Registers
f
as a function to be invoked when the document has loaded and is ready to be
manipulated. If the document is already ready,
f
is invoked immediately as a method of
the document object. Returns a jQuery object that contains only the document object.
jQuery Selector Grammar
The jQuery selector grammar is very similar to the CSS3 selector grammar, and it is explained
in detail in §19.8.1. The following is a summary:
Simple tag, class and ID selectors
* tagname .classname #id
Selector Combinations
A B B as a descendant of A
A > B B as a child of A
A + B B as a sibling following A
A ~ B B as a sibling of A
Attribute Filters
[attr] has attribute
[attr=val] has attribute with value val
[attr!=val] does not have attribute with value val
[attr^=val] attribute begins with val
[attr$=val] attribute ends with val
[attr*=val] attribute includes val
[attr~=val] attribute includes val as a word
[attr|=val] attribute begins with val and optional hyphen
Element Type Filters
:button :header :password :submit
:checkbox :image :radio :text
:file :input :reset
jQuery
946 | Client-Side JavaScript Reference
60
Element State Filters
:animated :disabled :hidden :visible
:checked :enabled :selected
Selection Position Filters
:eq(n) :first :last :nth(n)
:even :gt(n) :lt(n) :odd
Document Position Filters
:first-child :nth-child(n)
:last-child :nth-child(even)
:only-child :nth-child(odd)
:nth-child(xn+y)
Miscellaneous Filters
:contains(text) :not(selector)
:empty :parent
:has(selector)
Basic jQuery Methods and Properties
These are the basic methods and properties of jQuery objects. They don’t alter the selection
or the selected elements in any way, but they allow you to query and iterate over the set of
selected elements. See §19.1.2 for details.
context
The context, or root element, under which the selection was made. This is the second
argument to
$()
or the Document object.
each(f(idx,elt))
Invoke
f
once as a method of each selected element. Stops iterating if the function returns
false
. Returns the jQuery object on which it was invoked.
get(idx):elt
get():array
Return the selected element at the specified index in the jQuery object. You can also use
regular square-bracket array indexing. With no arguments,
get()
is a synonym for
toArray()
.
index():int
index(sel):int
index(elt):int
With no argument, return the index of the first selected element among its siblings. With
a selector argument, return the index of the first selected element within the set of ele-
ments that match the selector
sel
, or -1 if it is not found. With an element argument,
return the index of
elt
in the selected elements, or -1 if it is not found.
is(sel):boolean
Return
true
if at least one of the selected elements also matches
sel
.
jQuery
Client-Side JavaScript Reference | 947
Client-Side
JavaScript
Reference
63
length
The number of selected elements.
map(f(idx,elt)):jQuery
Invoke
f
once as a method of each selected element and return a new jQuery object that
holds the returned values, with
null
and
undefined
values omitted and array values
flattened.
selector
The selector string originally passed to
$()
.
size():int
Return the value of the
length
property.
toArray():array
Return a true array of the selected elements.
jQuery Selection Methods
The methods described in this section alter the set of selected elements, by filtering them,
adding new elements, or using the selected elements as starting points for new selections. In
jQuery 1.4 and later, jQuery selections are always sorted in document order and do not con-
tain duplicates. See §19.8.2.
add(sel, [context])
add(elts)
add(html)
The arguments to
add()
are passed to
$()
, and the resulting selection is merged with the
current selection.
andSelf()
Add the previously selected set of elements (from the stack) to the selection.
children([sel])
Select children of the selected elements. With no argument, select all children. With a
selector, select only matching children.
closest(sel, [context])
Select the closest ancestor of each selected element that matches
sel
and is a descendant
of
context
. If
context
is omitted, the
context
property of the jQuery object is used.
contents()
Select all children of each selected element, including text nodes and comments.
end()
Pop the internal stack restoring the selection to the state it was in before the last selection-
altering method.
eq(idx)
Select only the selected element with the specified index. In jQuery 1.4, negative indexes
count from the end.
jQuery
948 | Client-Side JavaScript Reference
Download from Wow! eBook <www.wowebook.com>
81
filter(sel)
filter(elts)
filter(f(idx):boolean)
Filter the selection so it only includes elements that also match the selector
sel
, that are
included in the array-like object
elts
, or for which the predicate
f
returns
true
when
invoked as a method of the element.
find(sel)
Select all descendants of any selected element that match
sel
.
first()
Select only the first selected element.
has(sel)
has(elt)
Filter the selection to include only those selected elements that have a descendant that
matches
sel
or that are ancestors of
elt
.
last()
Select only the last selected element.
next([sel])
Select the next sibling of each selected element. If
sel
is specified, exclude those that do
not match.
nextAll([sel])
Select all of the siblings following each selected element. If
sel
is specified, exclude those
that do not match.
nextUntil(sel)
Select the siblings following each selected element up to (but not including) the first
sibling that matches
sel
.
not(sel)
not(elts)
not(f(idx):boolean)
This is the opposite of
filter()
. It filters the selection to exclude elements that match
sel
, that are included in
elts
, or for which
f
returns
true
.
elts
may be a single element
or an array-like object of elements.
f
is invoked as a method of each selected element.
offsetParent()
Select the nearest positioned ancestor of each selected element.
parent([sel])
Select the parent of each selected element. If
sel
is specified, exclude any that do not
match.
parents([sel])
Select the ancestors of each selected element. If
sel
is specified, exclude any that do not
match.
jQuery
Client-Side JavaScript Reference | 949
Client-Side
JavaScript
Reference
72
parentsUntil(sel)
Select the ancestors of each selected element up to (but not including) the first one that
matches
sel
.
prev([sel])
Select the previous sibling of each selected element. If
sel
is specified, exclude those that
do not match.
prevAll([sel])
Select all of the siblings before each selected element. If
sel
is specified, exclude those
that do not match.
prevUntil(sel)
Select the siblings preceding each selected element up to (but not including) the first
sibling that matches
sel
.
pushStack(elts)
Push the current state of the selection so that it can be restored with
end()
, and then select
the elements in the
elts
array (or array-like object).
siblings([sel])
Select the siblings of each selected element, excluding the element itself. If
sel
is specified,
exclude any siblings that do not match.
slice(startidx, [endidx])
Filter the selection to include only elements with an index greater than or equal to
startidx
and less than (but not equal to)
endidx
. Negative indexes count backward from
the end of the selection. If
endidx
is omitted, the
length
property is used.
jQuery Element Methods
The methods described here query and set the HTML attributes and CSS style properties of
elements. Setter callback functions with an argument named
current
are passed the current
value of whatever it is they are computing a new value for. See §19.2.
addClass(names)
addClass(f(idx,current):names)
Add the specified CSS class name or names to the
class
attribute of each selected element.
Or invoke
f
as a method of each element to compute the class name or names to add.
attr(name):value
attr(name, value)
attr(name, f(idx,current):value)
attr(obj)
With one string argument, return the value of the named attribute for the first selected
element. With two arguments, set the named attribute of all selected elements to the
specified
value
or invoke
f
as a method of each element to compute a value. With a single
object argument, use property names as attribute names and property values as attribute
values or attribute computing functions.
jQuery
950 | Client-Side JavaScript Reference
73
css(name):value
css(name, value)
css(name, f(idx,current):value)
css(obj)
Like
attr()
, but query or set CSS style attributes instead of HTML attributes.
data():obj
data(key):value
data(key, value)
data(obj)
With no arguments, return the data object for the first selected element. With one string
argument, return the value of the named property of that data object. With two argu-
ments, set the named property of the data object of all selected elements to the specified
value
. With one object argument, replace the data object of all selected elements.
hasClass(name):boolean
Returns
true
if any of the selected elements includes
name
in its
class
attribute.
height():int
height(h)
height(f(idx,current):int)
Return the height (not including padding, border, or margin) of the first selected element,
or set the height of all selected elements to
h
or to the value computed by invoking
f
as
a method of each element.
innerHeight():int
Return the height plus padding of the first selected element.
innerWidth():int
Return the width plus padding of the first selected element.
offset():coords
offset(coords)
offset(f(idx,current):coords)
Return the X and Y position (in document coordinates) of the first selected element, or
set the position of all selected elements to
coords
or to the value computed by invoking
f
as a method of each element. Coordinates are specified as objects with
top
and
left
properties.
offsetParent():jQuery
Select the nearest positioned ancestor of each selected element and return them in a new
jQuery object.
outerHeight([margins=false]):int
Return the height plus the padding and border, and, if
margins
is
true
, the margins of the
first selected element.
outerWidth([margins=false]):int
Return the width plus the padding and border, and, if
margins
is
true
, the margins of the
first selected element.
jQuery
Client-Side JavaScript Reference | 951
Client-Side
JavaScript
Reference
64
position():coords
Return the position of the first selected element relative to its nearest positioned ancestor.
The return value is an object with
top
and
left
properties.
removeAttr(name)
Remove the named attribute from all selected elements.
removeClass(names)
removeClass(f(idx,current):names)
Remove the specified name or names from the
class
attribute of all selected elements. If
a function is passed instead of a string, invoke it as a method of each element to compute
the name or names to be removed.
removeData([key])
Removed the named property from the data object of each selected element. If no prop-
erty name is specified, remove the entire data object instead.
scrollLeft():int
scrollLeft(int)
Return the horizontal scrollbar position of the first selected element or set it for all selected
elements.
scrollTop():int
scrollTop(int)
Return the vertical scrollbar position of the first selected element or set it for all selected
elements.
toggleClass(names, [add])
toggleClass(f(idx,current):names, [add])
Toggle the specified class name or names in the
class
property of each selected element.
If
f
is specified, invoke it as a method of each selected element to compute the name or
names to be toggled. If
add
is
true
or
false
, add or remove the class names rather than
toggling them.
val():value
val(value)
val(f(idx,current)):value
Return the form value or selection state of the first selected element, or set the value or
selection state of all selected elements to
value
or to the value computed by invoking
f
as a method of each element.
width():int
width(w)
width(f(idx,current):int)
Return the width (not including padding, border, or margin) of the first selected element,
or set the width of all selected elements to
w
or to the value computed by invoking
f
as a
method of each element.
jQuery
952 | Client-Side JavaScript Reference
Documents you may be interested
Documents you may be interested