jQuery CSS Methods - css method

css method

jQuery css method is used to apply css properties to each element in the set of matched elements.
$(selector).css(PropertyName, PropertyValue);

Single css property example

jQuery css method is used to apply single css property to div element here.
<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$( "div" ).css("color", "blue");
});
</script>
</head>
<body>
<div>Welcome to jQuery learning!</div>
</body>
</html>
Output:
Welcome to jQuery learning!

jQuery css method for multiple css properties

jQuery css method is used to apply multiple css properties to div element here.
$(selector).css({PropertyName1:PropertyValue1, PropertyName2:PropertyValue2, ...});

Multiple css properties example

<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$( "div" ).css({"color": "blue", "font-weight": "bold"});
});
</script>
</head>
<body>
<div>Welcome to jQuery learning!</div>
</body>
</html>
Output:
Welcome to jQuery learning!

jQuery css property name value

jQuery css method is used to get css property name value.
$(selector).css(property_name);

Get property name value example

<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
document.write($( "div" ).css("color"));
});
</script>
</head>
<body>
<div style="color: blue;">Welcome to jQuery learning!</div>
</body>
</html>
Output:
rgb(0, 0, 255)

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^