Open In App
Related Articles

How to set background color for an elements using jQuery ?

Improve Article
Save Article
Like Article

In this article, we will set the background color for an element using jQuery. To add the background color, we use css() method. The css() method in JQuery is used to change style property of the selected element. The css() in JQuery can be used in different ways. The css() method can be used to check the present value of the property for the selected element.



Return value: It will return the value of the property for the selected element. 



<!DOCTYPE html>
<html lang="en">
        How to set background color
        for an elements using jQuery?
    <!-- Import jQuery cdn library -->
    <script src=
        $(document).ready(function () {
            $("button").click(function () {
                    .css("background", "green");
<body style="text-align: center;">
    <h1 style="color: green;">
        How to set background color
        for an elements using jQuery?
    <p>GeeksforGeeks computer science portal</p>
    <input type="text">
    <button>Click Here!</button>


Before Click Button:

After Click Button:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 31 Dec, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials