How to change css styles of elements using jQuery




Sometimes when you work with jQuery,  you want to change css-style of elements. There are two common ways to do it: 1 – to change class of element, 2 – add css attribute

1. How to add class to element using jQuery

For example, you have a class 'green'

And you want to apply this class to your element. So you need to add class:

Note, that element with class '.ms-formtable' will have two classes - '.ms-formtable' and 'green'. If after some condition or action you want to return to defaults, then user removeClass:

 

2. How to add style to element using jQuery

If you can’t create a new class for a page, you can add a css-property for an object. The syntax is like this:

In this case you apply a new property to the object. To undo it you should use something like this:

 



MarkiMarta.com. Notes of web-specialist
Since 2009
18+
Disable copy text with jQuery

This code disables context menu, cutting, copying and dragging text. Sometimes you need it. Just add the code to a...

Close