Tryit Editor v1.8

Source Code:
<!DOCTYPE html> <html> <body> <p id="p1">Click the button to locate where "locate" first occurs.</p> <p id="p2">0</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var str=document.getElementById("p1").innerHTML; var n=str.indexOf("locate"); document.getElementById("p2").innerHTML=n+1; } </script> </body> </html>
Result:
W3Schools.com - Try it yourself