0

I have variable that get's value of checked radio button named: parentcheck I wanna check if parentcheck is checked and =0 or if not checked. Tried if(parentcheck=='') for "not checked". it doesn't work.

var parentcheck = $(".parentcheck:checked").val();

            if(parentcheck=='0'){
                    $("#parent").hide();
                }
            if(parentcheck==''){
                    $("#parent").hide();
                }

4 Answers 4

2
if(!$('.parentcheck:').is(':checked')) {
    $('#parent').hide();
}
Sign up to request clarification or add additional context in comments.

Comments

1

First off, that selector you use will only return you elements with the class .parentcheck which are actually checked. By definition, that means every element it returns (as it always returns a set in jQuery) will be checked, so if the element you're looking for isn't checked then it won't be in the set. Something like this might be what you're after:

if (! $(".parentcheck").is(":checked")) {
    $("#parent").hide();
}

Comments

1

I actually can't get your question, it should help you.

var $check = $('.parentCheck');
if ($check.val() == '' || toString($check.val()) == "0") {
    // do your stuff
}

if ($check.attr('checked')) {
    // checked, do your stuff
}
else { 
    // is not checked, do another stuff
}

Comments

1

Use .attr('checked')=='checked'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.