O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

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:


Cover of Head First JavaScript Programming


What happens if you try to get the attribute of an element that does not exits?