matt
matt

Reputation: 2997

jQuery: Select dropdown by HTML

I've written a jQuery function that allows me to select an option from a dropdown using the option's HTML.

$.fn.select = function( option ) {
    $(selector +  ' option').each(function() {
        if ($(this).text() == option)
            $(selector).val($(this).val());
    });
    return this;
};

The function works perfectly fine, except with options that contain ampersands (&). In this case, it will fail to properly select the corresponding option.

Is there any way I can make this work?

I am aware that there already exists a select function for jQuery; however, it seems that my select function is able to overwrite the existing function.

Upvotes: 1

Views: 545

Answers (2)

Madhur
Madhur

Reputation: 2219

Seems to be working right with &, Whats the problem ?

Though replacing & with & would be better.

Upvotes: 1

rahul
rahul

Reputation: 7663

try replace & to & and then compare them

Upvotes: 1

Related Questions