What is removeClass in jQuery

jQuery

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

Classes p.65 jQuery in a nutshell

The attribute class is a special and important attribute, as its content has a special meaning for both the appearance (CSS) and 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");

hasClass (name) p.67 jQuery in a nutshell

checks whether an element belongs to a class

With hasClass (name) it can be checked whether an element belongs to a class. If so, she delivers true back.

Example:

if ($ ("# output"). hasClass ("blackV")) {

$ ("# Output"). AddClass ("blackV")

}

removeClass (name) p.67 jQuery in a nutshell

Remove elements from a class

With removeClass (name) elements can be removed from a class.

Example:

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

$ ("# Paragraph"). RemoveClass ("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 property's value.

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>

Example:

<script type="text/javascript">

$ (document) .ready (function () {

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

var state of the display = 0;

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

if (statusDerAn Anzeige == 0) {

if ($ ("# output"). hasClass ("blackV")) {

$ ("# Output"). RemoveClass ("blackV"). RemoveClass ("orangeH");

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

$ ("# Output"). Text ("In foreground color orange");

state of the display = 1;

}

else {

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

$ ("# Output"). Text ("In foreground color orange");

state of the display = 1;

}

}

else {

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

$ ("# Output"). AddClass ("blackV"). AddClass ("orangeH");

$ ("# Output"). Text ("In Foreground Color Black");

state of the display = 0;

}

});

});

</script>

Output:

My color is changed!