Z
Zhang Weiwu
Dear all
How does javascript realiablily tell if a variable is a reference to an
HTML Element "<select>", without causing browser to pop up error message?
if (variable.constructor == HTMLElementSelect)
// doesn't work, Firefox complain no such property if variable is undefined
if (typeof variable == "object" && variable.constructor == HTMLElementSelect)
// doesn't work, IE complain object do not have this property "constructor"
// However, IE do show constructor of objects if it's not Element Object
if (variable.tagName == "select")
// doesn't work if variable is undefined.
if (typeof variable == "object" && variable.tagName == "select")
// doesn't work, complain property do not exist if object is an non DOM Node
if (typeof variable == "object" && variable.tagName && variable.tagName == "select")
// must the working solution be this complicated?
Thanks, sorry I didn't read other people's code enough to have seen how
tho handle this neatly. And I didn't google out either.
How does javascript realiablily tell if a variable is a reference to an
HTML Element "<select>", without causing browser to pop up error message?
if (variable.constructor == HTMLElementSelect)
// doesn't work, Firefox complain no such property if variable is undefined
if (typeof variable == "object" && variable.constructor == HTMLElementSelect)
// doesn't work, IE complain object do not have this property "constructor"
// However, IE do show constructor of objects if it's not Element Object
if (variable.tagName == "select")
// doesn't work if variable is undefined.
if (typeof variable == "object" && variable.tagName == "select")
// doesn't work, complain property do not exist if object is an non DOM Node
if (typeof variable == "object" && variable.tagName && variable.tagName == "select")
// must the working solution be this complicated?
Thanks, sorry I didn't read other people's code enough to have seen how
tho handle this neatly. And I didn't google out either.