0

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');
        }
    });  

3 Answers 3

0

If you use .attr() it should be

attr('checked','checked');
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

I tried both of them and still no result, but in the generated HTML the values are changing properly...
can you post the updated code or a jsFiddle link of what you've tried?
0

how about:

    var isChecked = $(this).is(':checked');
    if (isChecked) {
        //do something
    } else {
        //do something
    }

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.