Search code examples
javascriptjquerycsslocaleaspdotnetstorefront

Hiding a link based on drop down list value selected


I need to write some jquery which will read what the current value in a drop down list is and then hides a particular link on the page.

The dropdown list is a locale selector. So when I select "english" I want the link to be hidden but when select French the link has to remain.

Can you show how i can do this? I want learn this. Thanks


Solution

  • How about this:

    function handleLang() {
        if ($('#select').val() == 'en') {
            $('#link').hide();
        } else {
            $('#link').show();
        }
    }
    $(function() {
        // hide/show on load
        handleLang();
    
        // hide/show when the language is changed (useful if the page doesn't reload)
        $('#select').change(handleLang);
    });