Erasing the last character (text)

56 views Asked by At

I'm trying erasing the last character on the "backspace" field when I'm clicking on "button" field.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <span id="log">abcdefghijklmnop</span>
    <div class="button" id="backspace">Backspace</div>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    <script type="text/javascript">
        $(function (){
            // backspace
            $( "#backspace" ).on( "click", function() {
                $('#logInfo').hide();
                $("#log").text().substr(0,this.length-1);
            });
        });
    </script>
</body>
</html>
1

There are 1 answers

0
Neeraj Amoli On BEST ANSWER
 $( "#backspace" ).on( "click", function() {
    $('#logInfo').hide();
    data = $("#log").text();
    $("#log").text(data.substr(0,data.length-1));
 });