miklleb
miklleb

Reputation: 3

jQuery <div> content swap script is not working with IE7 & IE8

The following thread provided me with a neat script to swap out div content and was authored by Carl Meyer.

Unfortunately the script does not work in IE7 & IE8 but works in Firefox 4+ and Chrome.

Does anyone know what i need to edit to get the script to work in IE7 & IE8?

Here is the script as i have edited it:

<script type="text/javascript" src="scripts/jquery-1.8.1.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    switches = $('#switches > div');
    slides = $('#slides > div');
    switches.each(function(idx) {
            $(this).data('slide', slides.eq(idx));
        }).hover(
        function() {
            switches.removeClass('active');
            slides.removeClass('active');             
            $(this).addClass('active');  
            $(this).data('slide').addClass('active');
        });
    });
</script>

<style type="text/css">
    #switches div.active {
      display: block;
    }   
    #slides div {
      display: none;
    }   
    #slides div.active {
      display: block;
    }   
</style>

<div id="switches" class="float_left">                      
 <div>switch 01</div>
 <div>switch 02</div>
 <div>switch 03</div>       
</div>

<div id="slides" class="float_left">
 <div class="active">(01) Slide content goes here</div>
 <div class="">(02) Slide content goes here</div>
 <div class="">(03) Slide content goes here</div>   
</div>

Upvotes: 0

Views: 328

Answers (1)

williamcarswell
williamcarswell

Reputation: 673

The switches and slides variables are not initialised and thus breaks in Internet Explorer, try adding 'var' infront

i.e.

var switches = $('#switches > div');

Upvotes: 1

Related Questions