Danny
Posts Too Much
Formerly Schnooble
Posts: 332
|
Post by Danny on Mar 18, 2007 22:45:49 GMT
is there a difference between using
if(td[x].className=='catbg'){
and
if(td[x].className.match(/catbg/i)){
I know the second one is like a regular expression but I just wanted to know if there was a difference.
|
|
|
Post by FireIndy on Mar 18, 2007 23:08:36 GMT
No there is no difference. They are both comparring. Except the bottom u have as incasesensitive. But the top is looking for an exact match.
|
|
Danny
Posts Too Much
Formerly Schnooble
Posts: 332
|
Post by Danny on Mar 19, 2007 0:24:46 GMT
thanks man
|
|
Ross
eCreations Staff
Posts: 1,768
|
Post by Ross on Mar 19, 2007 23:57:54 GMT
Yes there is a difference The first looks for an exact match, it is saying that the class must be exactly equal to "catbg" The second one on the other hand just requires the class name to contain the string "catbg", it would still match against "catbg2" or "notthecatbg". Of course, you could use ^and $ to force the regular expression to match the start and end of the class name, but if you're only checking for an exact match, then use the first one. Only use the second one if you need to check for a particular RegEx pattern.
|
|
Danny
Posts Too Much
Formerly Schnooble
Posts: 332
|
Post by Danny on Mar 20, 2007 0:09:08 GMT
thanks alot again I should know these things
|
|
|
Post by FireIndy on Mar 20, 2007 0:46:41 GMT
Wouldnt the bottom one also get the className anyway? Edit: Sorry if I was wrong.
|
|
Ross
eCreations Staff
Posts: 1,768
|
Post by Ross on Mar 21, 2007 17:17:55 GMT
Wouldnt the bottom one also get the className anyway? Edit: Sorry if I was wrong. Yes it would match a classname of "catbg" and thus return true, but it would also return true for a classname of "catbg2" or "notthecatbg" whereas the first one wouldn't
|
|