This article mainly introduces information about css styles for JQuery operation elements. For more information about how to use Javascript to change the styles of page elements, see. One of the methods is to change the page meta.
In traditional Javascript, we usually process HTML
The classname feature of Dom is implemented. jQuery provides three methods to implement this feature,
Although they are similar to traditional methods, they save a lot of code. Or that sentence-
"JQuery makes JavaScript code concise !"
1. addClass ()-add CSS class
The Code is as follows:
$ ("# Target"). addClass ("newClass ");
// # Target indicates the ID of the element to add a style.
// NewClass refers to the CSS Class Name
2. removeClass ()-remove the CSS class
The Code is as follows:
$ ("# Target"). removeClass ("oldClass ");
// # Target indicates the ID of the element to be removed from the CSS class.
// OldClass refers to the CSS Class Name
3. toggleClass ()-add or remove a CSS class: If the CSS class already exists, it will be removed;
Conversely, if the CSS class does not exist, it will be added.
The Code is as follows:
$ ("# Target"). toggleClass ("newClass ")
// If the element whose ID is "target" has defined the CSS style, it will be removed;
// Conversely, the CSS class "newClass" will be assigned to this ID.
In practical use, we often define these CSS classes first, and then use Javascript events to trigger
Send (such as clicking a link) to change the page element style. In addition, jQuery provides a method
HasClass ("className") is used to determine whether an element has been assigned to a CSS class.
The following is a complete example.
The Code is as follows:
Image flashing
Haha