<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="wrapper-demo">
<div id="dd" class="wrapper-dropdown-1" tabindex="1">
<span>Gender</span>
<ul class="dropdown" tabindex="1">
<li data-js="m"><a href="#">Male</a></li>
<li data-js="f"><a href="#">Female</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
*,
*:after,
*:before {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
background: #fff;
}
.wrapper-demo {
margin: 20px 0 0 0;
}
.wrapper-demo:after {
clear: both;
content: "";
display: table;
}
/* DEMO 1 */
.wrapper-dropdown-1 {
position: relative;
width: 200px;
padding: 10px;
margin: 0 auto;
background: linear-gradient(top, #ededed 0%, #f9f9f9 100%); /* FF3.6+ */
background: gradient(linear, left top, left bottom, color-stop(0%,#ededed), color-stop(100%,#f9f9f9)); /* Chrome,Safari4+ */
background: linear-gradient(top, #ededed 0%,#f9f9f9 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(top, #ededed 0%,#f9f9f9 100%); /* Opera 11.10+ */
background: linear-gradient(top, #ededed 0%,#f9f9f9 100%); /* IE10+ */
background: linear-gradient(to bottom, #ededed 0%,#f9f9f9 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ededed', endColorstr='#f9f9f9',GradientType=0 ); /* IE6-9 */
border:1px solid #A2A2A2;
color: #525252;
outline: none;
cursor: pointer;
font-family: 'Helvetica', 'Arial', sans-serif;
}
.wrapper-dropdown-1:after {
content: "";
width: 0;
height: 0;
position: absolute;
right: 16px;
top: 50%;
margin-top: -6px;
border-width: 6px 0 6px 6px;
border-style: solid;
border-color: transparent #adadad;
}
.wrapper-dropdown-1 .dropdown {
/* Size & position */
position: absolute;
top: 100%;
left: 0;
right: 0;
/* Styles */
background: #FAFAFA;
border:1px solid #adadad;
list-style: none;
font-weight: normal; /* Cancels previous font-weight: bold; */
/* Hiding */
opacity: 0;
pointer-events: none;
}
.wrapper-dropdown-1 .dropdown li a {
display: block;
text-decoration: none;
color: #525252;
padding: 10px 20px;
}
/* Hover state */
.wrapper-dropdown-1 .dropdown li:hover a {
background: #E0E0E0;
}
/* Active state */
.wrapper-dropdown-1.active .dropdown {
opacity: 1;
pointer-events: auto;
}
/*no blue outlines with li or a is focus or active*/
.wrapper-dropdown-1 .dropdown:active, .wrapper-dropdown-1 .dropdown:focus {
outline:none;
}
.wrapper-dropdown-1 .dropdown li a:focus, .wrapper-dropdown-1 .dropdown li:focus {
outline:none;
background-color:#E0E0E0;
}
.wrapper-dropdown-1.active:after {
border-color: #adadad transparent;
border-width: 6px 6px 0 6px ;
margin-top: -3px;
}
.wrapper-dropdown-1.active {
background-color:#E9E9E9;
border-width: 1px 1px 0px 1px;
}
/* No CSS3 support */
.no-opacity .wrapper-dropdown-1 .dropdown,
.no-pointerevents .wrapper-dropdown-1 .dropdown {
display: none;
opacity: 1; /* If opacity support but no pointer-events support */
pointer-events: auto; /* If pointer-events support but no pointer-events support */
}
.no-opacity .wrapper-dropdown-1.active .dropdown,
.no-pointerevents .wrapper-dropdown-1.active .dropdown {
display: block;
}
$('.wrapper-demo').on('click', function() {
$('#dd').toggleClass('active');
});
$('.dropdown > li').on('click', function() {
var displayVal = $(this).text();
var realVal = $(this).data('js');
$('.wrapper-demo span').html('Gender: '+displayVal);
console.log(realVal); //this displays "m" or "f" depending on your choice
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |