Is jQuery a class

JavaScript - jQuery - CSS manipulations

Attributes p.63 jQuery in a nutshell

Every HTML element can have attributes. jQuery provides several functions to access these attributes.

attr (name)

Read out attribute

This function returns the value of an attribute if one is present in the element.

attr (name, value) p.64 jQuery in a nutshell

Set attribute to a specific value

To set an attribute to a certain value, the first parameter is the Surname of the attribute and the value of the attribute as the second parameter. The return value of this function is the jQuery object with the current result set.

Example:

$ ("a # myLink"). attr ("rel", "Author");

attr (properties)

set multiple attributes at once

If you want to set several attributes at once, you have to attr pass a simple object as a parameter that represents the desired attribute names and values ​​as a key / value relationship. The return value of this function is the jQuery object with the current result set.

Example:

$ ("a.home"). attr ({

rel: 'library',

Href: 'http://www.jquery.com'

});

attr (name, fn) p.65 jQuery in a nutshell

Set attributes to the return value of a function

removeAttr (name) p.65 jQuery in a nutshell

Remove attributes

Classes p.65 jQuery in a nutshell

The attribute class is a special and important attribute, as its content has a special meaning both for the appearance (CSS) and for jQuery. Elements that belong to a class can be easily found with the selector engine. What is special is that several elements can belong to one class, but also that an element can be a member of several classes.

addClass (name) p.66 jQuery in a nutshell

Set class affiliation

With the method addClass (name) become all selected elements of the class Surname added. If an element is already a member of the class, nothing changes; the class name then only occurs once. You can also add elements of several classes by assigning addClass several times.

Example:

$ ("# Paragraph"). AddClass ("orangeV");

$ ("# Paragraph"). AddClass ("orangeV"). AddClass ("blackH");

CSS p.84 jQuery in a nutshell

In jQuery, the appearance of HTML elements can easily be changed by setting CSS properties.

css (name) p.84 jQuery in a nutshell

Output the value of a CSS property

The method css (name) returns the current value for the CSS property in the parameter Surname is specified.

Example:

$ ("# Paragraph"). Css ("color");

css (name, value) p.85 jQuery in a nutshell

set a single CSS property

Becoming the method css (name, value) Passing two strings as parameters, jQuery interprets the first as a CSS property and the second as the value of the property.

Example:

$ ("# Paragraph"). Css ("color", "green");

css (properties) p.84 jQuery in a nutshell

sets several CSS properties

Example:

$ ("p"). css ({

color: "green",

fontSize: "12pt",

backgroundColor: "orange"

});

CSS manipulation

Example:

<script type="text/javascript" src="jquery.js"> </script>

<script type="text/javascript">

$ (document) .ready (function () {

$ ("# Output"). AddClass ("orangeV"). AddClass ("blackH");

// Two classes are assigned

});

</script>

Alternative:

The attr () method can also be used.

<script type="text/javascript">

$ (document) .ready (function () {

$ ("# Button"). Click (function () {

$ ("# Output"). Attr ("class", "orangeV");

});

});

</script>

Alternative:

or the method css ()

<script type="text/javascript">

$ (document) .ready (function () {

$ ("# Button"). Click (function () {

$ ("# Output"). Css ("color", "green");

});

});

</script>

Output:

My color is changed!