Wednesday, April 22, 2015

JavaScript String search() Method

Sample Code :

<!DOCTYPE html>
<html>
<body>
<p>Click the button to search a string for "W3Schools", and display the position of the match.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
    var str = "Visit W3Schools!";
    var n = str.search("W3Schools");
    document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>


Result :

Click the button to search a string for "W3Schools", and display the position of the match.



6


0 comments:

Post a Comment

Thanks For Coming The Page.