Working with CSS(CSS Manipulation)
Working with CSS(CSS Manipulation)
These methods are used to manipulate CSS specially by getting and setting CSS-related properties of elements.
.css( )
This method get the CSS style property of the first matched element..
Example :
|
Above code display the color code of the clicked 'div' .
.height( )
This method get the height of the first matched element.
Example :
$("p").height()); // returns height of paragraph.$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
.innerHeight( )
This method return the height for the first element including padding but not border. This method is not applicable to window and document objects; for these, use .height() instead.
Example :
Following code get the innerHeight of a paragraph :
|
.innerWidth( )
This method return the width for the first element including padding but not border. This method is not applicable to window and document objects; for these, use .height() instead.
Example :
Following code will get the innerWidth of a paragraph :
|
.offset( )
This method get the current coordinate of the matched element, relative to the document.
Example :
This method returns the offset of the second paragraph
|
.outerHeight( )
This method get the outer Height from the first matched element, including padding and border.This method is not applicable to window and document objects; for these, use .height() instead.Example :
The following code get the outer Height of a paragraph :
|
.outerWidth( )
This method get the outer width from the first matched element, including padding and border.This method is not applicable to window and document objects; for these, use .height() instead.
Example :
The following code get the outer Width of a paragraph :
|
.position( )
This method get the coordinates of the first matched element , relative to the offset parent.
Example : 1
Following code return the position of the second paragraph :
<body> |
.scrollLeft( ) 2
This method get the current horizontal position of the scroll bar for the first matched element.
Example :
Following code get the current horizontal position of the scroll bar for the first 'p' : 3
|
.scrollTop( )
This method get the current vertical position of the scroll bar for the first matched element. 4
Example :
Following code get the current vertical position of the scroll bar for the first 'p' :
|
.width( )
This method get the width of the first matched element.
Example : 6
Following are some example of 'width()' method :
$("p").width());
//returns width of paragraph.
$(window).width(); // returns width of browser viewport
$(document).width(); // returns width of HTML document
Learn from experts! Attend jQuery Training classes. 7