Sign in
Log inSign up

Dom Manipulation In Javascript Confusion

Default profile photo
Anonymous
·May 14, 2018
<input type="text" name="task" id="task">

Approach : 1 
const taskInput = document.querySelector('#task');
console.log(taskInput.value)

Approach 2
const taskInput = document.getElementById('#task');
console.log(taskInput.value)

Approach 3
const taskInput = document.querySelector('#task').value;
console.log(taskInput)

In the above code snippets which approach is more suitable ,I am following approach 1, it is working fine but unable to execute approach 2 and approach 3.Is approach 2 and approach 3 is invalid .

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct