How to get the ID of an active link
问题 I'd like to display the ID of the active link in my navbar through an alert, but I'm not sure how to do this with my current Bootstrap 3 classes. I was thinking of something like alert( $('li').hasClass( "active" ).attr('id') ); but sadly that doesn't work. Bootply HTML: <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="collapse navbar-collapse navHeaderCollapse"> <ul class="nav navbar-nav navbar-right"> <li class = "active"><a id = "tab1" href = "#"