As some may know that a styling style selects an element, this is a nightmare, literally impossible without any javascript cheating. The new datalist in HTML5 can serve the same purpose, since the user is presented with a list of options, and the value is written to the input text box.
The restriction here is that the list does not appear until the user begins to enter text in the text box, and even then only possible matches based on their input are displayed. The behavior I want is that, as soon as it focuses on the field, the entire list of options becomes visible.
So I have this code - view on jsbin
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>Input - Datalist</title> </head> <body> <input list="categories"> <datalist id="categories"> <option value="Breakfast">Breakfast</option> <option value="Brunch">Brunch</option> <option value="Lunch">Lunch</option> <option value="Dinner">Dinner</option> <option value="Desserts">Desserts</option> </datalist> </body> </html>
and I'm trying to show this with this Javascript:
var catVal = document.getElementsByTagName("input")[0], cat = document.getElementById("categories"); catVal.style.fontSize = "1.3em"; catVal.addEventListener("focus", function(event){ cat.style.display = "block"; }, false);
Any help would be appreciated
Greetings
source share