Computer Science, asked by spider1573, 1 year ago

Make a web page in javascript and take background colour as an input from user

Answers

Answered by Anonymous
0

Hi

<!DOCTYPE html>

<html lang="en">

<head>

 <meta charset="UTF-8">

 <meta name="viewport" content="width=device-width, initial-scale=1.0">

 <meta http-equiv="X-UA-Compatible" content="ie=edge">

 <title>JavaScript Program To Change Background</title>

</head>

<body>

 <input type="text" id="uiColor">

 <button id="uiChangeBgBtn">Change Background</button>

 <script>

   const uiColor = document.getElementById('uiColor');

   const uiChangeBgBtn = document.getElementById('uiChangeBgBtn');

   uiChangeBgBtn.addEventListener('click', changeBg);

   function changeBg () {

     const bgColor = uiColor.value;

     document.body.style = `background-color: ${bgColor}`;

   };

 </script>

</body>

</html>


You can put rgb, rgba, hex, color name.. whatever kind of color in that input field.


Attachments:
Similar questions