javascript - Responding to an HTML element to change background and text of a DIV using jQuery -
i have element returns value of either true
or false
when run $('#myid').val()
.
once true or false returned, want have particular div
change background color green true or red false.
if ($('#myid').val()) { code should return div text , green background } else { code should return div text , red background }
you have convert string bool evaluate properly. have button in fiddle return value.
html:
<div id="mydiv"> <input id="myid" value="false"/> <input id="mybtn" type="button" value="submit"/> </div>
jquery:
$('#mybtn').on('click', function () { $('#mydiv').css('background', (($('#myid').val() == "true") ? 'green' : 'red')); });