<!DOCTYPE html>
<
html
>
<
head
>
<
title
>Change Label When Radio Button Checked</
title
>
<
link
rel
=
"stylesheet"
href
=
</
head
>
<
body
class
=
"p-4"
>
<
h1
class
=
"text-2xl font-bold mb-4"
>
Change Label When Radio Button Checked
</
h1
>
<
div
class
=
"flex flex-col space-y-4"
>
<
div
>
<
input
type
=
"radio"
id
=
"radio1"
name
=
"radio"
>
<
label
for
=
"radio1"
class="block
bg-gray-300 rounded-md p-4 w-60">
Label Text
</
label
>
</
div
>
<
div
>
<
input
type
=
"radio"
id
=
"radio2"
name
=
"radio"
>
<
label
for
=
"radio2"
class="block
bg-gray-300 rounded-md p-4 w-60">
Another Label Text
</
label
>
</
div
>
</
div
>
<
script
>
const radioBtn = document.getElementById('radio1');
const label = document.querySelector('label[for="radio1"]');
radioBtn.addEventListener('change', (event) => {
if (event.target.checked) {
label.textContent = 'New Label Text';
} else {
label.textContent = 'Label Text';
}
});
</
script
>
</
body
>
</
html
>