skip to Main Content
<input type="color" id="color" placeholder="Enter color">
  <div class="select">

const color = document.getElementById("color").value;

In short I wanna build a program that lets user input the color, and that the value of the color needs to be sent to another program without the hashtag.

I was wandering is there a way that I remove Hashtag from Const color.
Would be great if I can keep the same const name.

2

Answers


  1. const colorInput = document.getElementById('color');
    
    colorInput.addEventListener('change', () => {
      const colorValue = colorInput.value.replace('#', '');
      console.log(colorValue);
    });
    <input type="color" id="color" placeholder="Enter color">

    a constant cannot be assigned a new value

    Login or Signup to reply.
  2. You cant change const color, but you can just send:

    color.replace('#', '')
    

    Output would be like ‘FFFFFF’ if previously it was ‘#FFFFFF’

    or you can use replace to value:

    const color = document.getElementById("color").value.replace('#', '')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search