jQuery Get And Set
jQuery get and set methods are used to get or set the style properties of the selected element.
jQuery get and set methods are used to get or set the style properties of the selected element.
jQuery css() method is used to set or get(return) the style properties of the selected HTML element.
You can find the general properties of the selected elements through the given below syntax.
$(selector).css("propertyName");
Source Code
$(document).ready(function () {
$("h2,h3").click(function () {
var color = $(this).css("color");
$("#result").html(color);
});
});
To set a single CSS property and value to the element, pass a single CSS property name and value as separate parameters to the css() method.
Source Code
$(selector).css("propertyName", "value");
You can also pass more than one CSS property and value inside the CSS() method. Let us see its general syntax.
$(selector).css({"propertyName":"value", "propertyName":"value", ...});
Source Code
$(document).ready(function () {
$(".btn-effect").click(function () {
$("h2,h3").css({ "background-color": "green", color: "white", padding: "10px" });
});
});