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.

jsfiddle

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

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -