Question

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.

Was it helpful?

Solution

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

Though replacing & with & would be better.

OTHER TIPS

try replace & to & and then compare them

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top