Css-dom operation

Source: Internet
Author: User

1.css ()

$ (' P '). CSS (' color ');//get <p> element font Color

$ (' P '). CSS (' Color ', ' red ');//set <p> element's font color is red

$ (' P '). css ({' font-size ': ' 30px ', ' Color ': ' Red '});//settings <p> elements multiple style properties

2.offset ()

Gets the relative offset of the element in the current view, with the returned object containing two properties, top and left, only valid for visible elements

var $p =$ (' P '). offset ();//Get offset for <p> element ()

var left= $p. left;//Get left Offset

var top= $p. top;//Get right Offset

3.position ()

Gets the relative offset of the element relative to the nearest position style property set to relative or absolute's grandparent, and the returned object contains two properties, the top and left

var $p =$ (' P '). Position ();//Get <p> element position ()

var left= $p. left;//Get left Offset

var top= $p. top;//Get right Offset

4.scrollTop () and ScrollLeft ()

Gets the distance from the top of the scroll bar of the element and the distance from the left, respectively.

var $p =$ (' P ');

var scrolltop= $p. scrolltop ();//Gets the distance of the element's scrollbar from the top

var scrollleft= $p. ScrollLeft ();//Gets the distance from the left side of the scrollbar of the element

$ (' textarea '). scrolltop (300);//The vertical scroll bar of the element scrolls to the specified position

$ (' textarea '). ScrollLeft (300);//The horizontal scroll bar of the element scrolls to the specified position

Css-dom operation

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.