Datalist or Select depending on browser support

361 Views Asked by At

I want to use datalist, but in case it's not supported by a browser I want do display a basic select. What's the simplest way to achieve this? I'd rather not use JavaScript (excepting simple solution without messing the code and HTML form). It could be PHP' if statement or something like picture tag, which chooses the best available image:

<picture>
  <source srcset="img.webp" type="image/webp">
  <source srcset="img.jpg" type="image/jpeg"> 
  <img src="img.jpg">
</picture>

I've got some solutions prepared, but I want to choose the best one. At this moment the best possible solution is to make two divs (datalist and select) and after page loading remove one div this way:

if ('options' in document.createElement('datalist'))
    $('#basicSelect').remove()
else
    $('#datalist').remove()

Above solution was taken from this question.

Thanks in advance.

0

There are 0 best solutions below