jquery - Getting all options in a select element -
i have select element user can add , remove options. when user done click save cannot figure out how options select. have found jquery selected need of them. tried this:
var str = ""; $("#wordlist").each(function () { str += $(this).text() + ","; }); alert(str);
but concatenates option 1 long string ends in comma.
that code says on box. expect have used $("#wordlist option")
options. guessing if options "this", "that" , "the other" got thisthatthe other,
, code (that text inside #wordlist element, includes options inside element. array performing .each()
on has single element: "thisthatthe other", iterate on once , add comma).
you want concatenate text of each of options in #wordlist (i think), try
var str = ""; $("#wordlist option").each(function () { str += $(this).text() + ","; }); alert(str);
to give string of words (like this,that,the other,
) if want array, instead this:
var arr = []; $("#wordlist option").each(function () { arr.push($(this).text()); }); alert(arr.join(", "));
Comments
Post a Comment