Search code examples
javascripthtmlinputcolors

Removing the Hashtag From stored value


<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.


Solution

  • 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('#', '')