user354625
user354625

Reputation: 557

Checkbox Issue with IE8 using jquery

I have this code

 $('#Submit').click(function(event) {
            var checked = $('.inputchbox'); ......IE8
            var ids= checked.map(function() {
                return $(this).val();
            }).get().join(',');
             alert(ids);
        });

This Code return all the values which is there for Checkboxbox (.inputchbox is class for the checkbox)

but If I give somethign like this

var checked = $('.inputchbox input:checkbox:checked');
or
var checked = $('.inputchbox input[type=checkbox]:checked');
or
var checked = $('.inputchbox input[name=chk]:checked');
or 
var checked = $('.inputchbox').find('input[type=checkbox]:checked');

if i am giving like this nothing is working for me I am not getting the result in IE8?

 var checked = $('.inputchbox'); .....this is working but I am getting the checkboxes ids its doesnot checking wheather its checked or not.. 

I need to get only checked chekcbox id's

thanks

Upvotes: 1

Views: 2841

Answers (3)

MvanGeest
MvanGeest

Reputation: 9661

How about

var checked = $('.inputchbox:checked');

? The problem with your snippets is that the space you're using is the descendant selector and will look down into the DOM. The .find() method does the same. g.d.d.c was correct in replying that .filter() instead of .find() should work equally well (but a marginal amount slower):

var checked = $('.inputchbox').filter(':checked');

Upvotes: 4

Matt
Matt

Reputation: 75327

A space in a selectors indicates an ancestor-descendant relationship, i.e. .inputchbox is an ancestor of your checkbox, which from your other example, seems incorrect.

Try:

$('input.inputchbox:checkbox:checked');

Etc.

Upvotes: 0

g.d.d.c
g.d.d.c

Reputation: 48038

When you include a space in your selector it implies children. If you want to get by class with attributes you need to do something like this: $('.inputchbox:checked')

Upvotes: 0

Related Questions