Skip to content

Gracefully handle missing elements #296

@jwestbrook

Description

@jwestbrook

Scenario

document.observe('dom:load',function(){

   $('div1').update('my div')

});

If the element div1 does not exist in the DOM then the js errors and nothing else past that line is ran. The error ends up being cannot read property of null which is not descriptive. (could be different in different browsers but still not the actual problem)

so question is

  1. This is expected behavior, devs should wrap the statements in if blocks
  2. We should throw a better error, "Element with id(s) div1 does not exist"
  3. Gracefully fail, or return an empty element to prevent the JS error and throw a warning

This applies to Element#down() as well

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions