Can I write this JQuery statement cleaner?
Posted
by Polaris878
on Stack Overflow
See other posts from Stack Overflow
or by Polaris878
Published on 2010-03-29T21:12:45Z
Indexed on
2010/03/29
21:13 UTC
Read the original article
Hit count: 208
JavaScript
|jQuery
Hello,
So I have the following:
var box = $(".MyCheckBox");
if (box[0].checked)
{
// Do something
}
else
{
// Do something else
}
Is there a better way of doing this using filters or something?
I know I can go:
$(".MyCheckBox")
.filter(function(index) {
return this.checked;
})
.each(function() {
// do something
});
But I need to do something in the else statement... easier way of doing this? Thanks!
© Stack Overflow or respective owner