Each function in jquery state

I got a solution. However, suppose I have to display the input text box for only one of the menus. How can i do this?

+3


source to share


1 answer


You have a selection error in select.#ch

, so it must be select > option:selected

either:

$("option:selected", this).each(function() {
    str += $(this).text() + " ";
});

      

However, I would rewrite the code like this:



$("select").change(function () {
    var str = $("option:selected", this).map(function() {
        return this.innerHTML;
    }).get().join(" ");

    $("div").text(str);
}).change();

      

DEMO: http://jsfiddle.net/MpjjE/

+7


source







All Articles