<body>
<input type="radio" id="txtElement3" />Voorgrond<br />
<input type="radio" id="txtElement2" />Achtergrond<br />
<input type="text" id="txtElement">
<button id="btnKnop1">Stel kleur in</button>
<div id="divResult">Voorbeeld tekst</div>
<script>
$(document).ready(function () {
$("#btnKnop1").on('click', function () {
if ($('#txtElement3').is(':checked')) {
var txtElement = $('#txtElement').val()
$('#divResult').css('color', txtElement)
} if ($('txtelement2').is(':checked')) {
var txtElement = $('#txtElement').val()
$('#divResult').css('background-color', txtElement)
}
})
})
</script>
</body>
I tried this, at first it did work, now it doesn’t work anymore.
How to change the div color, and background color when radio button is checked and on button click?
2
Answers
Changes I did:
For the radio button with label Achtergrond has id
txtElement2
but in the code you wrotetxtelement2
and also there is no#
before it.