Solved

Jquery checkbox and tag creation not working in IE8

Posted on 2014-02-25
5
830 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 57

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 53

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 57

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call a VB.net function in Javascript 6 52
Add Rows on a Table 8 54
Presenting my portfolio on the web? 11 53
Can't see json data in ajax call to Highcharts 2 30
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 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