Javascript Remove First Or Last Character In A String

How To Delete A Char From The Start Or The End Of A String Using Javascript  

delete a character from the start or the end of a string using javascript


In This Javascript Tutorial we will See How To Delete The Char At The Beginning Of A String Or At The End On Button Click Event In JS And Netbeans Editor .


Project Source Code:

    
<!DOCTYPE html>
<html>
    <head>
        <title>Javascript: Clear Char</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
        <p id="pText">0123456789</p>
        <button onclick="clearChar()">clear</button>
        
        <script>
            
            function clearChar(){
                
                var pt = document.getElementById("pText");
                // remove char from the beginning
                pt.innerHTML = pt.innerHTML.substring(1,pt.innerHTML.length);
                //
                // remove char from the end
                pt.innerHTML = pt.innerHTML.substring(0,pt.innerHTML.length-1);
                
            }
            
        </script>    
    </body>
</html>



Share this

Related Posts

Previous
Next Post »