I have a select and I want to clone it, then append after it with the same selected option.
HTML
<select>
<option value="0">test0</option>
<option value="1">test1</option>
<option value="2">test2</option>
</select>
javascript
(function($){
$('select').change(function(){
$clone = $(this).clone();
$(this).after($clone);
});
})(jQuery)
jsFiddle
http://jsfiddle.net/willHsu/3tRR9/
The way I find is to use
var value = $(this).children('option:selected').val();
to find the value then choose as a selected option. So I know the way to solve it.
but I still wonder why clone()
method can't copy the selected option status?
can anyone give me a reasonable explanation?