I'm trying to check whether an html element with a certain id exists before doing some operations on that.
How can I check whether an id exists or not with dojo?
I saw in javascript we can use try catch. But i like a more clean way.
edit:
Doing it like this:
 var a = dojo.byId('myId');
 if(a){
     // something
 }
                In dojo, it's just the same as plain javascript. You should do:
var elem = dojo.byId('myId');
 if(elem != null){
     // something
 }
Hope this helps. Cheers
Use getElementById() - it returns null if no element matches, otherwise it returns a reference to the matching element. So:
var el = document.getElementById('someid');
if (el != null) {
  // element exists; do something, e.g.,
  alert(el.value);
}
(P.S. I don't know how to do it using dojo, but you don't need to...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With