2

Having trouble converting this to jsx, i know the tag itself in html represents jsx but when i add it to a new file thats a .js it just reads my code as text? it just displays my code as text on the webpage (this code works on an html page, its an input box where a user would input an email for a newsletter)

<html>
<body>
   ...styling code elements
   ...styling code elements

<button  class="join" id = "join"> join </button>
  
        <script>
            let email = document.getElementById("email")
            document.getElementById("join").onclick = () => {
                console.log(email.value)
                fetch("/sendemail?email=" + email.value, {
                    method: "POST"
                }).then((res) => {
                    // success
                    alert("success")
                }).catch((err) => {
                    // error 
                    alert(err)
                })
            }
        </script>
   </body>
</html>

1 Answer 1

1

You need to point your script HTML element tag to the .js file using the src attribute. Then, place your text that is in between the script tags into the .js file itself.

<script src="main.js"> </script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.