1

I am trying to hide the calendar icon that appears next to a input of type date. I have no problem hiding it using css.

::-webkit-calendar-picker-indicator { display: none; }

However I only want to hide it in certain circumstances so need to hide with jquery or javascript but what ever I try it will not hide.

$("::-webkit-calendar-picker-indicator").css("display", "none");

Primarily I am only concerned with chrome.

How do I hide this webkit element using jquery?

Tim Long
  • 393
  • 1
  • 5
  • 17

1 Answers1

0

Detect Webkit, then add a class:

if (navigator.userAgent.indexOf('AppleWebKit') != -1) {
  //Add any other conditions here
  $('input[type=date]').addClass('webkitDate');
}
.webkitDate::-webkit-calendar-picker-indicator {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="date" />
sbgib
  • 5,580
  • 3
  • 19
  • 26