SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Custom checkbox jQuery

    I have i problem with a jQuery function.
    My objective is to make custom checkboxes and it works fine except in IE.

    input.is(':checked') keeps returning false when it should return true.
    So every time i click on the checkbox it keeps returning false in IE
    It works fine in Firefox and Crome.

    What am I doing wrong?
    Is there an issue with is(':checked') in explorer?

    Code:
    $(function() {
    	$(':checkbox').checkbox();	
    });
    
    (function($) {
    	jQuery.fn.checkbox = function(){
    		$(this).each(function(){
    			var input = $(this);
    			var label = $('label[for='+input.attr('id')+']');
    			
    			label.click(function(){
    				if (input.is(':checked')) {
    					label.removeClass('checked'); 
    				}
    				
    				else {
    					label.addClass('checked');
    				}
    				alert(input.attr('id').is(':checked'));
    			})
    	});
    };
    })(jQuery);

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abo2512 View Post
    I have i problem with a jQuery function.
    My objective is to make custom checkboxes and it works fine except in IE.
    Looks like you had a small error in your alert:
    Code:
    alert(input.attr('id').is(':checked'));
    If you take of the .attr('id') in there it should work.

    (Working example http://jsfiddle.net/GeekyJohn/D35PA/)
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doooooooooh as Homer Simpson would have said :-)
    Thank you for your help buddy

    Cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •