JQuery CSS


Using JQuery library developers can enhance their websites without worrying about browsers and their versions as long as the browsers have JavaScript enabled.

Most of the JQuery CSS Methods do not modify the content of the jQuery object and they are used to apply CSS properties on DOM elements.

Different types of Jquery CSS methods :

  1. css( name )
    • This method returns a style property on the first matched element.
    • Example:- var c = $(this).css("font-size");
  2. css( name, value )
    • This method Set a single style property to a value on all matched elements.
    • Example:- $(this).css("font-size","12px");
  3. css( properties )
    • This method set a key/value object as style properties to all matched elements.
    • Example:- $("li").eq(2).css({"color":"red", "background-color":"green"});
  4. height( val )
    • This method set the CSS height of every matched element.
    • Example:-$("#data").height( "12px" );
  5. height( )
    • Get the current computed, pixel, height of the first matched element.
    • Example:- var c = $('#data').height();
  6. innerHeight( )
    • Gets the inner height (excludes the border and includes the padding) for the first matched element.
    • Example:-var height = $('#data').innerHeight();
  7. innerWidth( )
    • Gets the inner width (excludes the border and includes the padding) for the first matched element.
    • Example:-var width = $('#data').innerWidth();
  8. offset( )
    • Get the current offset of the first matched element, in pixels, relative to the document
    • Example:-var offset = $(div).offset();
  9. offsetParent( )
    • Returns a jQuery collection with the positioned parent of the first matched element.
    • Example:- var offset = $(div).offsetParent();
  10. outerHeight( [margin] )
    • Gets the outer height (includes the border and padding by default) for the first matched element.
    • Example:-var height = $(div).outerHeight();
  11. outerWidth( [margin] )
    • Gets the outer Width (includes the border and padding by default) for the first matched element.
    • Example:-var width = $(div).outerWidth();
  12. position( )
    • Gets the top and left position of an element relative to its offset parent.
    • Example:-var position = $(div).position();
  13. scrollLeft( val )
    • When a value is passed in, the scroll left offset is set to that value on all matched elements.
    • Example:-$("div.demo").scrollLeft(300);
  14. scrollLeft( )
    • Gets the scroll left offset of the first matched element.
    • Example:- var val = $("div.demo").scrollLeft();
  15. scrollTop( val )
    • When a value is passed in, the scroll top offset is set to that value on all matched elements.
    • Example:- $("div.demo").scrollTop(300);
  16. scrollTop( )
    • Gets the scroll top offset of the first matched element.
    • Example:- var val = $("div.demo").scrollTop();
  17. width( val )
    • Set the CSS width of every matched element.
    • Example:- $("div.demo").width(300);
  18. width( )
    • Get the current computed, pixel, width of the first matched element.
    • Example:- $("p").offsetParent().addClass('redColor');


Example on Jquery CSS : Download from here

Share it

6 comments:

Post a Comment