jQuery Styles


Set Style


$("Element").addClass("Class")

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")


$("Element").removeClass("Class")

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


$("Element").toggleClass("Class")

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


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

("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:


$("Element").offset()

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


Element Width Height


$("Element").width()

Gets the width of an element


$("Element").width("val")

Sets the width of an element


$("Element").height()

Get the height of an element


$("Element").height("val")

Sets the height of an element




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook