Skip to content

Instantly share code, notes, and snippets.

@carlosrojaso
Created May 15, 2014 10:35
Show Gist options
  • Save carlosrojaso/8b055bd3541452cfdc85 to your computer and use it in GitHub Desktop.
Save carlosrojaso/8b055bd3541452cfdc85 to your computer and use it in GitHub Desktop.
CSS, Styling, & Dimensions
// Setting CSS properties.
$( "h1" ).css( "fontSize", "100px" ); // Setting an individual property.
// Setting multiple properties.
$( "h1" ).css({
fontSize: "100px",
color: "red"
});
// Working with classes.
var h1 = $( "h1" );
h1.addClass( "big" );
h1.removeClass( "big" );
h1.toggleClass( "big" );
if ( h1.hasClass( "big" ) ) {
...
}
// Basic dimensions methods.
// Sets the width of all <h1> elements.
$( "h1" ).width( "50px" );
// Gets the width of the first <h1> element.
$( "h1" ).width();
// Sets the height of all <h1> elements.
$( "h1" ).height( "50px" );
// Gets the height of the first <h1> element.
$( "h1" ).height();
// Returns an object containing position information for
// the first <h1> relative to its "offset (positioned) parent".
$( "h1" ).position();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment