Linas
Linas

Reputation: 4408

Jquery select element error

I have a problem with element selection, i have a form and i want to run each function for each form select box, here is my code:

$("#profile_form select").each(function(i){
    var seen = {};
    $(this + 'option').each(function() {
        var txt = $(this).text();
        if (seen[txt])
            $(this).remove();
        else
            seen[txt] = true;
    });
});

Now my problem is with $(this + 'option') part, if i try to select only select menu it works fine, but i need to select option and if i do that i get:

Uncaught Error: Syntax error, unrecognized expression: [object HTMLSelectElement]option

what am i doing wrong?

Upvotes: 0

Views: 2037

Answers (2)

Asdfg
Asdfg

Reputation: 12253

Try this

 $('option', this).each(...)

Upvotes: 2

Frédéric Hamidi
Frédéric Hamidi

Reputation: 263147

$(this + "option") tries to add a string to a DOM element, which is probably not what you want. You might be looking for:

$(this).find("option")

Or, alternatively:

$("option", this)

Upvotes: 2

Related Questions