|
.style( "style_property" [, "new_style_value" ] )
This function helps to get a specified style value of an element. style_property is mandatory input to this function.
This function also sets the style value of an element using the second parameter.
Parameters
Returns
Example 1
This example fetches and shows few style properties of div. Click on "Get Style Info".
JS
HTML
CSS
$.domLoaded(function() {
$.get("#btn1").on("click", function() {
var box = $.get("#box");
// Get few styles
var backColor = box.style("background-color");
var borderWid = box.style("border-width");
var color = box.style("color");
var height = box.style("height");
$.get("#msg").html("background-color : " + backColor
+ "<br/>border-width : " + borderWid
+ "<br/>color : " + color
+ "<br/>height : " + height);
});
});
Result
Example 2
Apply different styles to div using .style(). This example applies background-color, border, width, height and color.
JS
HTML
CSS
$.domLoaded(function() {
var box = $.get("#box");
$.get("#btn1").on("click", function() {
// Get Background Color
box.style("background-color", "yellowgreen");
});
$.get("#btn2").on("click", function() {
// Set width and Height
box.style("height", "100px");
box.style("width", "100px");
});
$.get("#btn3").on("click", function() {
// Set Border and Color
box.style("border", "10px solid #000");
box.style("color", "#fff");
});
});
Result
| ||||||||||||||||||||
