Skip to content

Instantly share code, notes, and snippets.

View carlosrojaso's full-sized avatar
🎯
Focusing

Carlos Rojas carlosrojaso

🎯
Focusing
View GitHub Profile
@carlosrojaso
carlosrojaso / gist:78f7c01c1e022c03be03
Created May 15, 2014 10:16
link The .attr() method
$( "a" ).attr( "href" ); // Returns the href for the first a element in the document
$( "#myId" ); // Note IDs must be unique per page.
$( ".myClass" );
@carlosrojaso
carlosrojaso / gist:02d285db4fefcc086eb7
Created May 15, 2014 10:21
Working with Selections
// The .html() method used as a setter:
$( "h1" ).html( "hello world" );
// The .html() method used as a getter:
$( "h1" ).html();
// Viewing the number of <h1> tags on the page.
var allHeadings = $( "h1" );
alert( allHeadings.length );
@carlosrojaso
carlosrojaso / gist:8b055bd3541452cfdc85
Created May 15, 2014 10:35
CSS, Styling, & Dimensions
// Setting CSS properties.
$( "h1" ).css( "fontSize", "100px" ); // Setting an individual property.
// Setting multiple properties.
$( "h1" ).css({
fontSize: "100px",
color: "red"
});
// Returns "lots of extra whitespace"
$.trim( " lots of extra whitespace " );
var myArray = [ 1, 2, 3, 5 ];
if ( $.inArray( 4, myArray ) !== -1 ) {
console.log( "found it!" );
}
<ul>
<ul>
<div class="test"></div>
<li id="foo1">foo</li>
<li id="bar1" class="test">bar</li>
<li id="baz1">baz</li>
<div class="test"></div>
</ul>
<div id="last"></div>
var foo = $( "li" );
// Disable #x
$( "#x" ).prop( "disabled", true );
// Enable #x
$( "#x" ).prop( "disabled", false );
// Event setup using a convenience method
$( "p" ).click(function() {
console.log( "You clicked a paragraph!" );
});
// Equivalent event setup using the `.on()` method
$( "p" ).on( "click", function() {
console.log( "click" );
});
// The hover helper function
$( "#menu li" ).hover(function() {
$( this ).toggleClass( "hover" );
});
// The toggle helper function
$( "p.expander" ).toggle( function() {
$( this ).prev().addClass( "open" );
}, function() {
$( this ).prev().removeClass( "open" );