SeattleAls SeattleAls - 1 year ago 76
Javascript Question

True-False condition inline on HTML element (checkbox)

I have this code:

<input type='checkbox'>

I want to make conditional using jQuery, for example, if
, then set it checked, if not then not.

May be something like:

<input type='checkbox' + if data[1].condition is false, unchecked + "'>

<input type='checkbox' + if data[1].condition is true, checked + "'>

Is there a way to set it inline? Something like:

<input type='checkbox' + data[1].condition | checked + "'>

Answer Source

There's not really a way to do this inline.

Using jQuery...

if(data[1].condition === false){
} else {
    $('input').prop('checked', true);