What happens if my attribute doesn’t exist in the element?
Remember what happens when you call
getElementById and the id doesn’t exist in the DOM? You get null. Same thing with
getAttribute. If the attribute doesn’t exist, you’ll get back null. Here’s how you test for that:
- 6. Interacting with Your Web Page: Getting to know the DOM
- Publisher: O'Reilly Media, Inc.
- Released: March 2014
What happens if you try to get the attribute of an element that does not exits?