Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to change input's values with jQuery. Values are changing properly, but the mark / unmark on the input box is not shown... I've tried if it is a problem with position or padding, but it is different problem and I'm kind of stacked.

Here is the code for changing input values:

    $('.AlarmsTreeView-Title input').click(function () {
        var isChecked = $(this).val();
        if (isChecked == "false") {
            $(this).attr('value', 'true').attr('checked','true');
        } else {
            $(this).attr('value', 'false').removeAttr('checked');
        }
    });  
share|improve this question
add comment

3 Answers

how about:

    var isChecked = $(this).is(':checked');
    if (isChecked) {
        //do something
    } else {
        //do something
    }
share|improve this answer
add comment

If you use .attr() it should be

attr('checked','checked');
share|improve this answer
add comment

Its recommended to use .prop() instead of .attr() for checked as you want to access the property "checked". So instead, you can use

$(this).prop('checked',true);

and

$(this).prop('checked',false);

Check out the documentation of prop() for more clarification.

share|improve this answer
 
I tried both of them and still no result, but in the generated HTML the values are changing properly... –  argh Sep 5 at 10:23
 
can you post the updated code or a jsFiddle link of what you've tried? –  Vandesh Sep 5 at 11:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.