Thursday 31 March 2016

html - Having a placeholder in a Select option





How would I get an equivalent placeholder in a select option? For example when you have a select list it may say in the field "City" then when clicking that it would show all cities in the options.


Answer



I think this is what you want .



HTML:






CSS :



#choice option { color: black; }
.empty { color: gray; }



JavaScript:



$("#choice").change(function () {
if($(this).val() == "0") $(this).addClass("empty");
else $(this).removeClass("empty")
});

$("#choice").change();



try this jsfiddle.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...