Using Javascript's typeof on DOM elements to check undefined (IE problem) -
i want iterate on list of dom elements (check boxes) , keep going long list defined. elements 'c1r1', 'c1r2', 'c1r3', etc. once hit undefined one, stop. problem seems using typeof dom elements.
here's offending code:
function domisdefined(idstring){ alert(idstring); var isitdefined = (typeof $(idstring) != 'undefined'); alert(isitdefined); return isitdefined; } ... for(i=1; domisdefined('c1r' + i); i++){ if($('c1r' + i).checked==true){ // stuff } }
the crux of problem line:
var isitdefined = (typeof $(idstring) != 'undefined');
the problem, found out, typeof $(idstring) returns object, whether defined or not. there way sort of thing? guess i'll put in try catch , check .checked property early, feels disgusting.
function domisdefined(idstring){ return !!document.getelementbyid(idstring); }
Comments
Post a Comment