简体   繁体   中英

getting value from input field in javascript

why do i keep get this error Uncaught TypeError: Cannot read properties of null (reading 'ariaValueText') when i run the code below

let myLeads = []
const inputEl = document.getElementById("input-el")

const inputBtn = document.getElementById("input-btn")


inputBtn.addEventListener("click", function(){

    myLeads.push(inputEl.value)
    console.log(myLeads)

})
 

You try this code is working perfectly for me

 let myLeads = [], inputEl = document.getElementById("input-el") const inputBtn = document.getElementById("input-btn") inputBtn.addEventListener("click", function() { myLeads.push(inputEl.value) console.log(myLeads) })
 <input id="input-el"> <button id="input-btn">Add</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM