Created
December 22, 2012 17:02
-
-
Save evanp/4359948 to your computer and use it in GitHub Desktop.
Adding a dropdown button with JQuery produces a usable dropdown
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test data-* attributes</title> | |
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div id="foo"> | |
<a href="#" class="btn" id="showdropdown">Show dropdown</a> | |
</div> | |
<div id="bar"> | |
</div> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/bootstrap.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$("#showdropdown").click(function() { | |
$("#bar").html('<div class="btn-group dropdown" id="messages">'+ | |
'<a class="btn dropdown-toggle btn-mini btn-success" data-toggle="dropdown" href="#">'+ | |
'<i class="icon-envelope icon-white"></i> '+ | |
'</a>'+ | |
'<ul class="dropdown-menu" role="menu">' + | |
'<li><a href="#">Four</a></li>' + | |
'<li><a href="#">Five</a></li>' + | |
'<li><a href="#">Six</a></li>' + | |
'</ul>' + | |
'</div>'); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment