Why .prop ("type") returns "text" on a datetime input?

Given a very simple code:

<html>
<body>
    <input type="datetime" id="TheInput"/>
    <script type="text/javascript" src="./jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function (){
            alert($("#TheInput").prop("type"));
        });
    </script>
</body>
</html>

You think the message will say "datetime", right? But apparently this is not so, it says "text." How and why does jQuery decide to ignore what I wrote for the type? Can't I write any arbitrary type for the "type" property and see how it passed me the message? Is there a list of what jQuery thinks certain types should be?

(And as an aside, don’t try to insert this into jsFiddle or codepen. For some reason both of them refuse to run my javascript. I don’t know if I am allowed to use “prop” or if I am not allowed to search by id, or what.)

+4
1

datetime .

. "text".

datetime-local.

console.log("type a : " + document.getElementById("a").type);
console.log("type b : " + document.getElementById("b").type);
<input id=a type=datetime>

<input id=b type=datetime-local>
Hide result

, ( attr jQuery), .

+4

Source: https://habr.com/ru/post/1682250/


All Articles