Quantcast
Channel: Javascript | Syntaxxx
Viewing all articles
Browse latest Browse all 6

How To: jQuery Add CSS and Remove CSS

$
0
0
There are multiple ways to add and remove CSS styling using jQuery. This is a quick tutorial to show you how. Sometimes you’ll have a need to, for example, have an element on the page change or disappear when the user performs an action, such as clicking or hovering. These are common tasks that frequently arise in web development. All of this can be achieved with just a little jQuery. If you need an introduction to jQuery, check out this post. We also have an introduction to JavaScript. Using jQuery css() to Add or Remove CSS Let’s say you have two buttons on the page and you want them to change the background color of a different element when they are clicked. This is how you do it with the jQuery css() function: The HTML… The CSS… The JavaScript… And the jQuery Add CSS Demo: What we’re doing here is whenever an element with the red-button class is clicked, the elements with a class of info-box have their background changed to red with this line: It’s that easy. Any CSS property and value can be added with this method. You can also change multiple CSS properties at once, using a […]

Viewing all articles
Browse latest Browse all 6

Trending Articles