Skip to Main Content
jQuery Pocket Reference
book

jQuery Pocket Reference

by David Flanagan
December 2010
Intermediate to advanced content levelIntermediate to advanced
160 pages
3h 31m
English
O'Reilly Media, Inc.
Content preview from jQuery Pocket Reference

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 Chapter 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):valueattr(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.

css(name):valuecss(name, value)css(name, f(idx,current):value)css(obj)

Like attr(), but query or set CSS style attributes instead of HTML attributes.

data():objdata(key):valuedata(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 arguments, 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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

jQuery and JavaScript Phrasebook

jQuery and JavaScript Phrasebook

Brad Dayley
Beyond jQuery

Beyond jQuery

Ray Nicholus
Head First jQuery

Head First jQuery

Ryan Benedetti, Ronan Cranley

Publisher Resources

ISBN: 9781449398958Supplemental ContentErrata Page