Created
September 28, 2015 13:51
-
-
Save bbrochier/254554ad3a45e2e99fff to your computer and use it in GitHub Desktop.
Select option with data
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
<select class="js-select"> | |
<option value="" data-link="http://www.waitbutwhy.com">Go to WBW</option> | |
<option value="" data-link="http://www.ted.com">Go to TED</option> | |
<option value="1">option 1</option> | |
</select> |
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
$('.js-select').change( | |
function() { | |
var linkRedirect = $(this.options[this.selectedIndex]).data('link'); | |
if (linkRedirect !== undefined) { | |
window.location.href = linkRedirect; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment