<html>
<head><script scr="http://code.jquery.com/jquery-1.8.2.min.js" ></script> </head>
<div id="cont1">
<select id="sel1" name="sel1" multiple>
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
</select>
</div>
<script>
$(function() {
$('#sel1 option').on('click', function(e){
if($(this).is(':selected')){
$('<input value="'+$(this).val()+'" />').appendTo('#cont1');
}
});
});
</script>
<html>
</body>
<html>
Why is this function not working? It gives the error ‘function not defined’.
The correct attribute name is
src:Also you should check your markup, since the correct one must contain the
<body>tag and one correctly placed pair of<html></html>tag.Additionally, consider using
changeevent for<select>element instead ofclickfor<option>, since it is more ‘cross browser’.