Solved

Jquery checkbox and tag creation not working in IE8

Posted on 2014-02-25
5
816 Views
Last Modified: 2014-02-25
Hi Experts,

I have got this code working in all browsers inc ie9 - except for ie8.

Its been driving me mad for over 3 hours now so thought I'd get an extra set of eyes on it.

Please Help

Jquery

if ($('#selected-breeds').children(".tag").length === 0) {
        $('#selected-breeds').hide();
    }

    $('#available-breeds :checkbox').click(function () {
        function selectedBreedFade() {
            if (!$('#selected-breeds').find('a').length) {
                $('#selected-breeds').fadeOut('fast');
            } else {
                $('#selected-breeds').fadeIn('fast');
            }

        }


        if ($(this).is(':checked')) {
            var checkedBreed = $(this).parent().next('td').find('label').text();
            $('<a class="tag">&times; <span>'+checkedBreed+'</span>').appendTo('#selected-breeds');
            selectedBreedFade();
        } else {
            var uncheckedBreed = $(this).parent().next('td').find('label').text();
            $('#selected-breeds').find('.tag span:contains(' + uncheckedBreed + ')').parent().fadeOut('fast').remove();
            selectedBreedFade();
        }

        $('#selected-breeds .tag').click(function () {
            var removedBreed = $(this).find('span').text();
            $(this).fadeOut('fast').remove();
            $('#available-breeds').find('label:contains(' + removedBreed + ')').parent().prev('td').find(':checkbox').attr('checked', false);
            selectedBreedFade()
        });

        $('#button-reset-search').click(function () {
            $('#selected-breeds').fadeOut();
            $('#selected-breeds').find('.tag').remove();
            $('#available-breeds :checkbox').prop('checked', false);
        });

    });

Open in new window


Html

<table id="available-breeds">
              <tbody>
                                   <tr><td><input type="checkbox" name="Breed" value="AA" /></td><td><label>Aberdeen Angus (AA)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AAX" /></td><td><label>Aberdeen Angus Cross (AAX)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AR" /></td><td><label>Angler Rotvieh (AR)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="ARX" /></td><td><label>Angler Rotvieh Cross (ARX)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AN" /></td><td><label>Ankole (AN)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AM" /></td><td><label>Armoricaine (AM)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AMX" /></td><td><label>Armoricaine Cross (AMX)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AU" /></td><td><label>Aubrac (AU)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AUX" /></td><td><label>Aubrac Cross (AUX)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="ALL" /></td><td><label>Australian Lowline (ALL)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AY" /></td><td><label>Ayrshire (AY)</label></td></tr>
                   <tr><td><input type="checkbox" name="Breed" value="AYX" /></td><td><label>Ayrshire Cross (AYX)</label></td></tr>
                              
</tbody>
              </table>
           

<div id="selected-breeds" class="form-row">
  <span class="form-title">Selected Breeds</span>
  <!-- Selected Breeds -->
</div>

Open in new window


Many thanks in advance
0
Comment
Question by:mcluff
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39885363
It seems to be choking on the line where you add the <a> to selected-breeds.

Try this instead
        // ... to line 18
        if ($(this).is(':checked')) {
            var checkedBreed = $(this).parent().next('td').find('label').text();
            // USE THIS LINE
            $('#selected-breeds').append($('<a/>').addClass('tag').html('&times; <span>'+checkedBreed+'</span>'));
             // INSTEAD OF THIS ONE
             // $('<a class="tag">&times; <span>'+checkedBreed+'</span>').appendTo('#selected-breeds');
            selectedBreedFade();
        } else {
            var uncheckedBreed = $(this).parent().next('td').find('label').text();
            $('#selected-breeds').find('.tag span:contains(' + uncheckedBreed + ')').parent().fadeOut('fast').remove();
            selectedBreedFade();
        }
        // .....

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39885369
Are you using jquery 2.x?  That will not support ie8.  You have to use 1.1x
0
 

Author Comment

by:mcluff
ID: 39885448
I'm using 1.10

The rest of my jquery works - its just this part.
0
 

Author Closing Comment

by:mcluff
ID: 39885451
Many thanks
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39885464
You are welcome - thanks for the points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question