Advertisement
elena1234

How to work with radio buttons ( JavaScript)

Nov 4th, 2021
1,531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lockedProfile() {
  2.     let allRadios = document.querySelectorAll('input[type=radio]');
  3.  
  4.     for (const radio of allRadios) {
  5.         radio.addEventListener("click", function () {
  6.             if (radio.value = "unlock" && radio.checked) { // how to work with radio buttons
  7.                 let profile = radio.parentElement;
  8.                 let buttonAboutContent = profile.lastElementChild;
  9.                 buttonAboutContent.addEventListener("click", function() {
  10.                     let hidenFields = profile.lastElementChild.previousElementSibling;
  11.                     if (buttonAboutContent.innerHTML == "Show more") {
  12.                         hidenFields.style.display = "block";
  13.                         buttonAboutContent.innerHTML = "Hide it";
  14.                     } else {
  15.                         hidenFields.style.display = "none";
  16.                         buttonAboutContent.innerHTML = "Show more";
  17.                     }
  18.                 });
  19.             }
  20.         })
  21.     }
  22. }
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement