jQuery Styles

Set Style


To get the HTML code for the selected element, add a class $("p") to the p element if you define a class style called .main {.....}.addClass("main")


As above, addClass("main") means to add style, this method is to remove the main style


This can be regarded as a synthesis of the first two methods. In simple terms: if there(does not exist) to delete(add) a class.

Defines Style


("Div").css("color") Gets the color of the font for this div.

$("Element").css(name, value)

Name represents the attribute name, and value represents the value. If you set the font color to # f00 for all divs, you only need $("div").css("color", "# f00");

$("Element").css({name: "value", name: "value"

, ...}) This method is to be able to set a number of elements of the style attributes at once, such as I want to set the font color is red for all p and the background color is green, it uses this method $("p").css({color: "# F00", background: "# 0f0"))); Of course, the brackets set up several items on the set of several Element Location:


This method returns two integer properties, top and left, which are only valid for visible elements.

Element Width Height


Gets the width of an element


Sets the width of an element


Get the height of an element


Sets the height of an element

Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.