Saturday, November 1, 2008

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

On Nov 1, 8:54 am, jetm <javier....@gmail.com> wrote:
> 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
> Tree

Maybe you want something like this instead?

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

No comments: