Forked from sleepdeprecation/duplicate-select-list.html
Created
May 30, 2018 15:27
-
-
Save mjurincic/4de918e60df64fdc796a70ac716878a5 to your computer and use it in GitHub Desktop.
Duplicate a select list using jQuery
This file contains hidden or 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>Duplicate a select list using jQuery</title> | |
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> | |
<script src="selectScript.js"></script> | |
</head> | |
<body> | |
<div id="d1"> | |
<select id="origSel"> | |
<option value="0">Zero</option> | |
<option value="1">One</option> | |
<option value="2">Two</option> | |
<option value="3">Three</option> | |
</select> | |
</div> | |
<div id="d2"></div> | |
</body> | |
</html> |
This file contains hidden or 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
$(document).ready(function () { | |
// copy the select area | |
$('#origSel').clone().attr('id', 'newSel').attr('name', 'newSel').appendTo($('#d2')); | |
// make the current value selected | |
$("#newSel > option[value='" + $('#origSel').val() + "']").attr('selected', 'selected'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment