Tips on eliminating the "other..." choice from the HTML color picker?

https://i.sstatic.net/73PuH.png

Is there a way to remove the "Other..." button from this code snippet?

This is the HTML code I am working with: The purpose of this code is to change the color of text by selecting colors from a dropdown menu. However, I only want the user to be able to choose from the specified list of colors.

<body>
  <p>This example demonstrates how to use the <code>&lt;input type="color"&gt;</code>
     control.</p>

  <label for="colorWell">Color:</label>
  <input type="color" value="#ff0000" id="colorWell" list="presetColors">
 <datalist id="presetColors">
   <option>#ff0000</option>
   <option>#00ff00</option>
   <option>#0000ff</option>
 </datalist>

  <p>Notice how the color of the paragraph changes when you manipulate the color picker.
     As you adjust the color picker, the color of the first paragraph
     will change as a preview (this uses the <code>input</code>
     event). Once you close the color picker, the <code>change</code>
     event is triggered, causing all paragraphs to change to
     the selected color.</p>
  <script src="scripts.js"></script>
</body>

Below is my JavaScript code:

var colorWell;
var defaultColor = "#0000ff";

window.addEventListener("load", startup, false);

function startup() {
  colorWell = document.querySelector("#colorWell");
  colorWell.value = defaultColor;
  colorWell.addEventListener("input", updateFirst, false);
  colorWell.addEventListener("change", updateAll, false);
  colorWell.select();
}

function updateFirst(event) {
  var p = document.querySelector("p");
  console.log(event.target.value);
  if (p) {
    p.style.color = event.target.value;
  }
}

function updateAll(event) {
  document.querySelectorAll("p").forEach(function(p) {
    p.style.color = event.target.value;
  });
}

    <label for="colorWell">Color:</label>
  <input type="color" value="#ff0000" id="colorWell" list="presetColors">
 <datalist id="presetColors">
   <option>#ff0000</option>
   <option>#00ff00</option>
   <option>#0000ff</option>
 </datalist>

Answer №1

If you're having trouble finding a delete button in the source code, you can also use JavaScript to remove it with the remove() method.

function remove(){
document.getElementById('target').remove();
}
<button id="target">Target</button>
<br><br>
<button id="remover" onclick="remove()">Remove Button</button>

If the button doesn't have an ID, you can utilize a similar method using jQuery:

$(function(){
 setInterval(function(){
  $('button').each(function(){
  var target = $(this);
  if(target.text() == 'Other...' || target.val() == 'Other...'){
   target.remove();
  }
  });
 }, 300); // 300 ms. you can change time range.
});

If the button is only loaded once with the document, you won't need to use the setInterval method

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble transmitting a file from the frontend to the server in your MERN project?

Struggling to transfer an image file from the React frontend to the server and encountering issues with sending the file: Below is the front end code snippet: useEffect(()=>{ const getImage=async ()=>{ if(file){ ...

Retrieving data from a Ruby class based on a specific condition

Currently, I have a code snippet that adjusts the formatting of an editing page based on the number of values a question contains. <% (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aa9b8484eadbdfcfec8cdcac3c5c484dbc6ece0 ...

"Place label and input fields side by side for a streamlined mobile display experience

My goal is to have the label and input field appear on the same line when there is enough width, but on separate lines when the width is too small. I have achieved this functionality, you can see it in action on this jsFiddle. Here is the HTML Code: < ...

Vue is throwing an error that parameter 'value' is implicitly assigned an 'any' type in TypeScript

Can anyone assist me with how I can correctly type the 'value' variable inside data to avoid the error message - Parameter 'value' implicitly has an 'any' type? <template> <v-sheet width="300" class=" ...

Accessing Django ManyToManyField via Ajax using its ID

Here are my models: class Topping(models.Model): name=models.CharField(max_length=24) class Pizza(models.Model): toppings=models.ManyToManyField(Topping) Now, onto the views: def get_pizza(request): if request.is_ajax(): pizza_list= ...

Caution: Attempting to update the state of a React component that is not mounted is prohibited. Ensure that the method is executed only once

Hey there! I'm having some trouble fetching the list of advertisers when the component mounts. It seems to be causing a memory leak issue. Any helpful suggestions are greatly appreciated! useEffect(() => { const fetchData = async () => { ...

Converting HTML to PDF using Node and Express

Searching for a way to directly render a webpage as a PDF in the browser through Express. Essentially, I want to convert the page into a PDF without saving it. I came across a module that can convert HTML or a URL into a PDF format. https://github.com/ma ...

Move router parameters to separate files to streamline and organize code

I have encountered a bit of an issue. I currently have the following code in my routing.js file where I define both my parameter and route. I have moved the routes to a separate router instance in my routing.js file, but I am struggling to separate the par ...

Unable to locate React.js refs within object

import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap'; export default class UserPicForm extends React.Component { constructor() { super(); // establish bindings this.handleSubmission = this.handleSubmission ...

"What is the best way to access and extract data from a nested json file on an

I've been struggling with this issue for weeks, scouring the Internet for a solution without success. How can I extract and display the year name and course name from my .json file? Do I need to link career.id and year.id to display career year cours ...

Proper syntax for jQuery's insertAfter() method when using selectors

I am working with a div <div id="imgDIV"><h4>My Debug DIV</h4></div> and I am trying to add a debug message at the top of the div, right after the first h4. This way, my most recent messages will be displayed at the top. $(' ...

Tips for implementing fixed width on child divs within a fixed parent div

Feel free to check out the link above. The menu is designed to have a fixed position, so when you scroll down it will stay visible, which is exactly what I intended. You'll notice there are numerous menu items within the Fixed menuWrapper which span ...

The JavascriptExecutor is unable to access the 'removeAttribute' property of a null object

While utilizing Javascript executor to remove the readonly attribute, I encountered an error message: Cannot read property 'removeAttribute' of null. I came across various discussions where users suggested that removing AdBlock from Chrome solve ...

Is it preferable to include in the global scope or the local scope?

When it comes to requiring a node module, what is the best approach? Should one declare the module in the global scope for accuracy and clarity, or does declaring it in the local scope make more sense? Consider the following examples: Global: let dns = r ...

Exploring the integration of HTTP server, websocket functionality, and the Express framework

Currently, I am in the process of building a website with NodeJs using "http-server", "express" and "web socket". The "http-server" is set to listen on port "8080" and the homepage ("index.html") features a basic login form. However, I have hit a roadbloc ...

CSS: width is functional but height is ineffective

When trying to adjust the width of a div, everything works smoothly, but the same cannot be said for adjusting the height. I attempted to experiment with the bootstrap carousel on codeply, but unfortunately, it didn't behave as anticipated: HTML code ...

Tips for reusing an SVG element that is embedded on the same page

My HTML5 page includes an embedded SVG icon element. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo="> </head> <body> ...

Passing Data from Child to Parent Components in ReactJS

I'm new to React and JavaScript, currently working on a website. I've encountered an issue with passing data between components from child to parent. Here's the scenario: In my App.js script, I'm using react-router-dom for routing. I ...

Is there a way to prioritize the table row background color over the cell input elements background color?

After a user selects a table row, the row is assigned the class below: tr.selected { background-color:#FFA76C; } However, if there are input fields in the cells with background colors, they end up overriding the row's background color. (For instance ...

Adjust the height of an element using percentages

Over at this JSFiddle link, they demonstrated splitting a page into 3 parts. However, when I adjust the width of #wrapper to 100%, everything works perfectly. So why does changing height:400px to height:100% cause it to fail? #wrapper { width: 400px; ...