Last active
May 9, 2016 08:28
-
-
Save zalom/ece5bf82b0e7962abd5bbac30ab72037 to your computer and use it in GitHub Desktop.
jQuey return each element's class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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