How to create a page with a btn and when clicked prompts to enter text which shd be shown&when text is clicked it must be delete | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to create a page with a btn and when clicked prompts to enter text which shd be shown&when text is clicked it must be delete

Use js with prompts

13th Oct 2019, 10:50 AM
Pavan Karthick M
Pavan Karthick M - avatar
1 Answer
0
Well without writing all the code myself here: 1)create a button element (through HTML or JS) 2)create function that prompts the user for input and store the input in a variable. In the same function (or a separate one) show the variable value (create a html element, add the value of the variable to the innerText property of the element. Then add the element to the DOM) 3) let the promptForInput function be triggered by the buttons onClick event. 4) For the element that shows the text, also add an onClick event and that triggers a function that removes the element from the DOM
2nd Sep 2020, 1:30 PM
Daniel Asherov