Javascript examples for jQuery:String
Use indexOf to check if string begins with another string
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> <script type="text/javascript"> $(function(){// w w w. j av a2s . c o m var foo = "asomething-something"; if(foo.indexOf("something") === 0) { console.log("works!"); } else{ console.log("doesn't work :("); } }); </script> </head> <body> </body> </html>