Search code examples
javascriptjqueryinternet-explorercross-browsershow-hide

Simple jQuery Hide/Show does not work in IE


$(document).ready(function () {
    $('#createGallery').hide();

    $("#newGallery").click(function () {
        $("#createGallery").show('slow');
    });
    $("#gallerySelect > option").not("#newGallery").click(function () {
        $("#createGallery").hide('slow');
    });
});

I can't figure out why. Seems easy enough. my HTML is in HAML. But its easy to understand if you don't know what HAML is. My HAML reads :

        #createGallery
          %span{ :style => "color:#1B75BC; font-size: 15px;" }
            new gallery
          %br
          %form{ :action => ""}
            %input{ :name => "tabname", :type => "text", :rows => "1", :cols => "30", :style => "height: 15px; width: 260px; margin-right: 40px;"}

        %span{ :style => "color:#1B75BC; font-size: 15px;" }
          gallery

        %form{ :action => ""}
          %select#gallerySelect{ :name => "Choose Gallery", :style => "width:260px" }
            %option{ :selected => "selected", :value => "QuickFact" }
              Choose Gallery
            %option{ :value => "QuickFact"}
              My Interior Design
            %option#newGallery{ :value => "QuickFact" }
              New Gallery
        %br

Solution

  • I don't believe that OPTION elements have click events. You'll want to attach the click handler to the SELECT element, and then check the option that was chosen.\

    (disclaimer: air-coded)

    $(document).ready(function(){
        $('#createGallery').hide();
        $("#gallerySelect").click(function () {
            if (this.options[this.selectedIndex].id == 'newGallery') {
                $("#createGallery").show('slow');
            } else {
                $("#createGallery").hide('slow');
            }
        });
    });