0

I'm using codes below to set value attributes to null but they only work for input fields. How can I do same thing for select boxes? When I clone, the first option (Select unit) should be selected.

VER 1:

var $cloned = $('#unit-field-cover div:last').clone();
$('#unit-field-cover div:last').after($cloned);
$('#unit-field-cover div:last select').attr({name:"size-unit[]", value:''});

HTML

<select name="size-unit[0]">
      <option value="">Select unit</option>
      <option value="Inches" selected="selected">Inches</option>
      <option value="Centimeters" >Centimeters</option>
      <option value="N/a">N/a</option>
</select>
BentCoder
  • 12,257
  • 22
  • 93
  • 165

1 Answers1

1

you can use val():

$('#unit-field-cover div:last select').val("");

FIDDLE EXAMPLE

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160