jQuery css() add CSS Properties to an Element

Introduction

jQuery css() method can add new CSS properties to an element.

It can also modify the existing properties values dynamically.

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Add CSS Property</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $("h1").css("color", "red");
        $("p").css({
            "background-color": "blue",
            "font-weight": "bold"
        });//w ww  . ja va 2  s.c  o  m
    });
</script>
</head>
<body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
</body>
</html>



PreviousNext

Related