JavaScript - String Contains A Substring

How To Check If A String Contains A Substring Using Javascript

javascript text includes



In This Javascript Tutorial we will see How To Virify If A Text Contains A Substring Using includes() On Buuton Click Event In JS Using Netbeans Editor .




Project Source Code:

<!DOCTYPE html>
<html>
    <head>

        <title>JavaScript Tutorial: Check If A String Contains A Substring</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <script>
            
            function check()
            {
                var pgh = document.getElementById('pgh').innerHTML.toLowerCase();
                var txt = document.getElementById('txt').value.toString().toLowerCase();
                
                if(pgh.includes(txt))
                {
                    alert('yes');
                }else{
                    alert('no');
                } 
            }
            
        </script>
        
    </head>

    <body>

        <p id="pgh">JavaScript Tutorial: Check If A String Contains A Substring</p>
        <input type="text" id="txt" name="txt"/>
        <button onclick="check();">Check</button>
        
    </body>

</html>


OUTPUT:

js text includes





Share this

Related Posts

Previous
Next Post »