Check First Char In String
I have input-box. I'm looking for a way to fire-up alert() if first character of given string is equal to '/'... var scream = $( '#screameria input' ).val(); if ( scream.charAt( 0
Solution 1:
Try this out:
$( '#screameria input' ).keyup(function(){ //when a user types in input box
var scream = this.value;
if ( scream.charAt( 0 ) == '/' ) {
alert( 'Boom!' );
}
})
Solution 2:
You need to add a keypress (or similar) handler to tell the browser to run your function whenever a key is pressed on that input field:
var input = $('#screameria input');
input.keypress(function() {
var val = this.value;
if (val && val.charAt(0) == '/') {
alert('Boom!');
}
});
Post a Comment for "Check First Char In String"