Rick Moss
Rick Moss

Reputation: 926

change the default selected option in a select via jquery

I have a select list where one option is selected by default when the page loads.

When a different option is selected, the html I view in Firebug does not change.

I have a button that makes copies of this element, and would like the copies to have the same selected value as this one, but they all have the default value selected.

How can I make the copies have the same selected values as the original?

Upvotes: 0

Views: 487

Answers (1)

jmar777
jmar777

Reputation: 39649

When you clone the element you should be able to set the cloned select's value to that of the original. E.g.,

var $select = $('#my-select'),
    $clone = $select.clone().val($select.val());
// I don't know where you really want the clone, just an example...
$clone.insertAfter($select);

Upvotes: 2

Related Questions