Skip to content

Instantly share code, notes, and snippets.

@pramithkm
Created November 28, 2013 08:34
Show Gist options
  • Save pramithkm/7688841 to your computer and use it in GitHub Desktop.
Save pramithkm/7688841 to your computer and use it in GitHub Desktop.
Get data attribute link and open in a new window.
<html>
<head>
<title>
Window Test
</title>
</head>
<body>
The Window Test
<div id="mylink" data-link="http://www.google.com">Google</a>
<div id="mydiv">
<select id="myoptions">
<option data-href="http://www.google.com">Google</option>
<option data-href="http://www.yahoo.com">Yahoo</option>
</select>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
/*
$('#mylink').click(function() {
alert($(this).attr('data-link'));
window.open($(this).attr('data-link'));
});*/
$( document ).ready(function() {
$('#myoptions').change(function(ev) {
window.open($(this).find('option:selected').data('href'));
ev.preventDefault();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment