Scroll width always returns undefined

I am doing a little program in which whenever it detects a change in input in a text field , it has to do something. But this does not work for me. So, I changed, I started giving a value in the console to check it, when it detects an input change, it always returns undefined . How can I get the size of the text entered by the user in pixels?

<!doctype html>
<html>
<head>
<style>
    input[type=text] {
        height: 20px;
        width: 100px;
    }
</style>
<script src="jquery.js"></script>
</head>
<body>
    <input type="text" id="func"></input>
</body>
<script>
    $("#func").change(function () {
      console.log($("func").scrollWidth);
    });
</script>
</html>
+4
source share
2 answers

. func . jQuery, # id (. ). , : $('#func').

-, DOM $('#func'), jQuery scrollWidth. , $('#func')[0].scrollWidth $('#func').get().scrollWidth.

jQuery width, : $('#func').width().

+2

scrollWidth - DOM-Element, jQuery, $('#func').get().scrollWidth .

0

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


All Articles