0

I have a code to change the date format and using input:before style where content: attr(data-date); is setting the new format.

The code works fine in Chrome but not in Firefox.

Is there any solution for firefox?

var today = new Date().toISOString().split('T')[0];
$("#datePicker").val(today);

$("input").on("change", function() {
    this.setAttribute(
        "data-date",
        moment(this.value, "YYYY-MM-DD")
        .format( this.getAttribute("data-date-format") )
    )
}).trigger("change")
input {
    position: relative;
    width: 150px; height: 20px;
}

input:before {
    position: absolute;
    top: 3px; left: 3px;
    content: attr(data-date);
    display: inline-block;
    color: black;
}

input::-webkit-datetime-edit, input::-webkit-inner-spin-button, input::-webkit-clear-button {
    display: none;
}

input::-webkit-calendar-picker-indicator {
    position: absolute;
    top: 3px;
    right: 0;
    color: black;
    opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<input type="date" id="datePicker" data-date="" data-date-format="DD MMM YYYY" value="">
Owais Ahmed
  • 1,364
  • 1
  • 30
  • 62
  • is there any fix @JaromandaX – Owais Ahmed Sep 27 '22 at 00:54
  • that wasn't the issue ... the issue is that firefox does not allow `::before` or `::after` on `` ... see [this answer](https://stackoverflow.com/a/37653939/5053002) - the TL;DR is, Chrome makes up its own rules – Jaromanda X Sep 27 '22 at 01:00

0 Answers0