I'm using the jQuery Clean Calendar Plugin, and it's working well. However, in my jQuery code, I want to check whether any '/' is present in textbox.val()
. Then I want to do some operations. How do I check if the value contains '/' in it?
views:
645answers:
2
+2
A:
Try
if (textbox.val().indexOf( "/") >= 0)
{
}
Same I guess will work for attribute:
if ($( "#id").attr( "some_attr").indexOf( "/") >= 0)
{
}
Artem Barger
2009-06-15 11:06:09
+1
A:
Just to suggest a slightly more concise way to do it, using ternary and match() instead:
$( "#id").attr( "some_attr").match('/') ? alert('got a forward slash') : alert('no forward slash');
karim79
2009-06-15 11:38:59
I love the ternary operator, but I'm thinking it may confuse the original poster. He seems relatively new to programming, and the if/then structure might make more sense than the () ? : ; structure.
Jonathan Sampson
2009-06-15 11:48:54
@Jonathan - I totally agree with you. I just felt like suggesting it as no-one else had, and to introduce a bit of variety.
karim79
2009-06-15 12:05:49