
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Get value from div with JavaScript resulting undefined?
Use document.getElementById().innerHTML for this. Following is the JavaScript code −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <div class='getValueFromDiv' id='getValue' contenteditable="true" onkeyUp='display()' style="color: red"></div> <script> function display(){ var storedValue = document.getElementById('getValue').innerHTML.value="This is the value"; console.log("The value is==="+storedValue); } </script> </body> </html>
To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.
Following is the output. When you will click the mouse and place the arrow key, you will get the following output.
The snapshot is as follows −
- Related Articles
- Get div height with vanilla JavaScript
- Get price value from span tag and append it inside a div after multiplying with a number in JavaScript?
- Get key from value in JavaScript
- Replace a value if null or undefined in JavaScript?
- JavaScript reduce sum array with undefined values
- How to remove blank (undefined) elements from JavaScript array - JavaScript
- Undefined in JavaScript
- JavaScript undefined Property
- How to get the first non-null/undefined argument in JavaScript?
- Setting a default variable value to undefined in a function - JavaScript?
- How to pass the value 'undefined' to a function with multiple parameters in JavaScript?
- JavaScript - know the value of GET parameters from URL
- How to get the value of div content using jQuery?
- Undeclared vs Undefined? In JavaScript
- JavaScript - array undefined element count

Advertisements