SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 74 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"


That leaves us with object detection, which checks to see whether the browser supports
a particular feature before it uses it. Object detection is much more reliable than string matching.
You shouldn??™t use it to check every method you want to use, but at least use it to check for
certain features.
For example, using getElementById is a good way to check that you??™re using a modern
DOM-aware browser:
if(document.getElementById)
{
var el = document.getElementById('myelement');
}
CHAPTER 2 n HTML, CSS, AND JAVASCRIPT 36
You can check whether the method exists by leaving off the brackets.
For a more comprehensive look at which methods are supported by which browsers,
check out the support table at www.webdevout.net/browser-support-dom.
Regular Expressions
As discussed earlier in this chapter, regular expressions are a way to accomplish string
matching (they??™re often referred to as regex or regexp). They are very popular, especially for
validating form data, but they are tricky beasts to tame. Some of the basics are covered here,
but the discussion is not exhaustive.
nNote Check out the Apress book Regular Expression Recipes by Nathan A. Good (ISBN: 1-59059-441-X)
for a more in-depth look at regular expressions.
A regular expression can be instantiated in one of two ways. The first is by using the regular
expression class:
var re = new RegExp('regex','ig');
The constructor takes two parameters, the first being the regular expression string to
match and the second parameter is the flags.


Pages:
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
Free English grammar and study guid Russian bride druga wojna światowa counter strike 1.6 hotel jelenia góra