What specifically is giving you trouble?
What is the specific functionality you are attempting to add to an HTML page?
Please post the code you have tried and maybe when can guide you to a solution.
I am just learning DOM and was trying to apply basic functionality like when we click on restart button everything should get erase, and I was trying text highlighter / text finder when I will enter that particular word it will highlight.
For us to guide you to a solution, you will need to show us your existing code and explain in detail what is working and what is not.
This is the question. I have just created the HTML but don’t know how to proceed for DOM.
- Take input numbers in form of string by separating numbers with
,. If there is an invalid number throw and error in id
#error. Display the input in
#display after clicking the button
- Implement js filter by writing code for even numbers and odd numbers separately and display them in
#display after clicking buttons
#even #odd respectively
- Implement Join method without any space between elements and display in
#display after clicking
JSON.stringify for displaying arrays and display strings normally
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<h3>JS Array Properties</h3>
<input type="text" id="input">
<div style="margin: 10px 0;">
<button id="even">Filter Even</button>
<button id="odd">Filter Odd</button>
<p id="error">Wrong Input!!</p>
const input = document.getElementById('input');
const addBtn = document.getElementById('add');
const display = document.getElementById('display');
const even = document.getElementById('even');
const odd = document.getElementById('odd');
const join = document.getElementById('join');
You need to add a click event listener for the
Add button. When clicked, you need to need to validate the input of numbers (it will actually be a string) entered are numbers. How would you think about approaching to accomplish this first?
Can we use numbers.toString ( ) and then use split( " ") to insert , in between them ?
The input is already a string, so there is no need to use
toString, but you could definitely use
split to create an array of elements and then iterate through the elements to check if they are all numbers.