Advertisement
Iv555

Untitled

Mar 30th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. function lockedProfile() {
  2. const profile = document.querySelector('.profile');
  3. const main = document.querySelector('#main');
  4. const BASE_URL = 'http://localhost:3030/jsonstore/advanced/profiles';
  5.  
  6. fetch(BASE_URL)
  7. .then((res) => res.json())
  8. .then((data) => {
  9. main.innerHTML = '';
  10. for (const { _id, username, email, age } of Object.values(data)) {
  11. const copyHTML = profile.cloneNode(true);
  12. const inputs = Array.from(copyHTML.querySelectorAll('input'));
  13. const button = copyHTML.querySelector('button');
  14. inputs[2].value = username;
  15. inputs[3].value = email;
  16. inputs[4].value = age;
  17. main.appendChild(copyHTML);
  18. const divToHideAndShow = copyHTML.querySelector('.user1Username');
  19. divToHideAndShow.style.display = 'none';
  20.  
  21. button.addEventListener('click', ShowMoreOrLess);
  22. }
  23. }).catch((err) => console.error(err));
  24.  
  25. function ShowMoreOrLess(e) {
  26. const currentDivProfile = e.currentTarget.parentNode;
  27. const divToHide = currentDivProfile.querySelector('div');
  28. const inputUnlock = currentDivProfile.querySelector('input[value="unlock"]');
  29.  
  30. if (inputUnlock.checked) {
  31. if (this.textContent === 'Show more') {
  32. divToHide.style.display = 'block';
  33. this.textContent = 'Hide it';
  34. }
  35. else if (this.textContent === 'Hide it') {
  36. divToHide.style.display = 'none';
  37. this.textContent = 'Show more';
  38.  
  39. }
  40. }
  41.  
  42. }
  43. }
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement