Skip to content

Instantly share code, notes, and snippets.

@zalom
Last active May 9, 2016 08:28
Show Gist options
  • Save zalom/ece5bf82b0e7962abd5bbac30ab72037 to your computer and use it in GitHub Desktop.
Save zalom/ece5bf82b0e7962abd5bbac30ab72037 to your computer and use it in GitHub Desktop.
jQuey return each element's class
/* A function to return class for each Bootstrap navbar elements */
// FIND DESCRIPTION BELOW THE CODE
$(function() {
$( "#navbar" ).click(function() {
$( "ul li" ).each(function( index ) {
var class_name = $( this ).attr("class");
if( class_name === "active" || class_name === "inactive"){
console.log( index + ": " + $( this ).attr("class") );
}
});
});
});
/*
General assumption is that your "li" elements contain class attributes
of "active" and "inactive".
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment