toggleClass
$("button").click(function(){
$("p").toggleClass("main");
});
each中的 false
Use return false to break out of each() loops(循环) early.
$( "div" ).each(function( index, element ) { // element == this $( element ).css( "backgroundColor", "yellow" ); if ( $( this ).is( "#stop" ) ) { $( "span" ).text( "Stopped at div index #" + index ); return false; } });