jquery Basics Tutorial: Style settings definition and element location

Source: Internet
Author: User

Article Introduction: jquery style settings and definitions.

style settings:
$ ("Element") . AddClass ("Class")
Get the HTML code for the selected element, if you define a class style called. Main{...}, then you can add $ ("P") to the P element. addclass ("main" )

$ ("Element"). Removeclass ("Class")
as above, AddClass ("main") means adding a style, and this method removes the main style

$ ("Element"). Toggleclass ("Class")
This can be considered as a synthesis of the first two methods. Simply put: Delete (add) A class if it exists (does not exist).

style definition:
$ ("Element"). CSS ("name")
represents a CSS style that obtains an element, such as $ ("div"). CSS ("color") indicates the font color of this div.

$ ("Element"). css (name,value)
name indicates the name of the property, and value represents the values. If you set the font color to #f00 for all Div, only $ ("div") is required. CSS ("Color", "#f00");


$ ("Element"). css ({name: ' value ', Name: ' Value ',......})
This method is designed to allow multiple style attributes to be set at once for an element, such as I want to set the font color red for all p and the background color green to use this method $ ("P"). CSS ({color: "#f00", Background: " #0f0 "}); Of course in the brackets in the set of several sets of several


element Position:
$ ("Element"). offset ()
This method returns two cosmetic properties, top and left, which are valid only for visible elements.

element Width Height:

$ ("Element"). width ()
get the width of an element
$ ("Element"). width ("val")
Set the width of an element

$ ("Element"). height ()
get an element height

$ ("Element"). height ("val")
set the height of an element


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.