También he leído algunas otras preguntas sobre el mismo tipo, pero no funciona. Estoy tratando de cambiar el texto dentro de la etiqueta <p> a Hello world. Lo hace en localhost pero no en la extensión de Chrome.
Mi manifiesto.json
{ "name": "Azura", "description": "Yes.! Azura", "version": "1.0", "manifest_version": 3, "permissions": ["tts"], "action": { "default_popup": "index.html" } }
Mi index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="./styles/css/style.css" /> <title>Azura</title> </head> <body> <div class="container"> <div> <h1 id="">Welcome</h1> </div> <div class="formHolder"> <form> <label for="fname">Search</label><br /> <input type="text" id="imgAddress" /><br /> <div onclick="myFunction()" id="submit">Submit</div> </form> </div> <p class="socials">socials here</p> <div class="powered">Powered by Azure - cognitive services</div> </div> <p id="textp">asdsad</p> </body> <script src="./backend/azureCognitive.js"></script> <script src="./backend/main.js"></script> </html>
Mi main.js
var submitBtn = document.getElementById("submit"); submitBtn.addEventListener(onclick, myFunction); function myFunction() { document.getElementById("textp").innerText = "Hello world"; var input = document.getElementById("imgAddress"); // console.log(input.value); }Todo esto funciona bien en localhost pero no funciona tan bien como en la extensión de Chrome. Cualquier ayuda será apreciada :)
Tu código está mal, creo. El detector de eventos debería ser así.
submitBtn.addEventListener('click', myFunction)