+ 14

I have a doubt.

I want to create a background color app. In which when we enter a color name by user input. the background color should be changed to the color entered. I don't know what should I use in js to do that. I have a few options. please choose one and answer. 1) document.body.style.backgroundColor.getElementbyId="" 2)document.getElementbyId 3)other comment below

9th Nov 2020, 7:11 AM
Queen👽
Queen👽 - avatar
4 Réponses
+ 8
first make an input tag and button tag in html and grab the button in javascript: HTML: <input id="color-input" /> <button id="submit-btn">Submit</submit> JS: let submitBtn = document.getElementById("submit-btn") Then define that what happens after you click on the button JS: submitBtn.onclick = function() { // NOW grab the input value to get the latest one let color = document.getElementById("color-input").value // be sure to put a .value otherwise you would get a whole tag instead of the value. docment.body.style.backgroundColor = color }
9th Nov 2020, 7:19 AM
maf
maf - avatar
+ 8
thnk u every one
9th Nov 2020, 7:26 AM
Queen👽
Queen👽 - avatar
+ 3
the below code selects the first input element in your html page ,and listens for input event ,whenever anything is inputted it assign the value to the desired element background color , document.querySelector("input").oninput=(e)=>{ document.getElementById("").style.backgroundColor=e.target.value }
9th Nov 2020, 7:19 AM
Abhay
Abhay - avatar
+ 2
Make code from any options that you want
9th Nov 2020, 7:18 AM
Sâñtôsh
Sâñtôsh - avatar