Saturday, November 1, 2008

[jQuery] Get All Values/Text and Add a ";"

In multiple select:

<select id="select1" name="select1" multiple="multiple">
<option>Flowers</option>
<option>Shrubs</option>
<option>Trees</option>
</select>

I want with a output like this: Flowers2; Shrubs2; Trees2;

I using this
var str = "";
$("#select2").each(function(){
str += $(this).text() + ";";
$("div").text(str);
});

for get all values/text from option and each one add ";"

But the problems is in the output show me this: Flowers2 Shrubs2
Trees2;

Why this result?

TIA,
JETM

No comments: