How to change CSS using jQuery?

Ignore the people that are suggesting that the property name is the issue. The jQuery API documentation explicitly states that either notation is acceptable:

The actual problem is that you are missing a closing curly brace on this line:


Change it to this:

$("#myParagraph").css({"backgroundColor": "black", "color": "white"});

Here’s a working demo:

function init() {
    $("h1").css("backgroundColor", "yellow");
    $("#myParagraph").css({ "backgroundColor": "black", "color": "white" });
    $(".bordered").css("border", "1px solid black");
<script src=""></script>
<div class="bordered">
    <p id="myParagraph">This is some paragraph text</p>

Leave a Comment