Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
578 B
1
Indexable
Never
  useEffect(() => {
    // Execute the JavaScript code after the component has mounted
    const requiredFields = document.querySelectorAll('input:required, select:required, textarea:required');
    console.log(requiredFields); // Corrected syntax

    requiredFields.forEach(field => {
      const label = field.previousElementSibling;

      if (label) {
        const asteriskSpan = document.createElement('span');
        asteriskSpan.className = 'required';
        asteriskSpan.textContent = ' *';
        label.appendChild(asteriskSpan);
      }
    });
  }, [loading]);
Leave a Comment