Skip to content

Instantly share code, notes, and snippets.

@bbrochier
Created September 28, 2015 13:51
Show Gist options
  • Save bbrochier/254554ad3a45e2e99fff to your computer and use it in GitHub Desktop.
Save bbrochier/254554ad3a45e2e99fff to your computer and use it in GitHub Desktop.
Select option with data
<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>
$('.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