I am trying to check if an html element exists with a specific identifier before performing some operations on it.
How to check if an id exists with dojo?
I saw in javascript we can use try catch. But I like a cleaner way.
edit:
Doing this:
var a = dojo.byId('myId'); if(a){ // something }
In dojo, it looks like regular javascript. You must do:
var elem = dojo.byId('myId'); if(elem != null){ // something }
Hope this helps. Greetings
Use getElementById() - it returns null if no elements match, otherwise it returns a link to the corresponding element. So:
getElementById()
var el = document.getElementById('someid'); if (el != null) { // element exists; do something, eg, alert(el.value); }
(PS I don't know how to do this using dojo, but you don't need ...)