javascript - How do I extract the name from HTML collection? -
here's step through of javascript.
i have htmlcollection, want loop through , extract object id of fileuploadcontrol. how do it?
here's code, how proceed?
function uploadimage(lnk) { var row = lnk.parentnode.parentnode; var rowindex = row.rowindex - 1; var abc = row.cells[2].getelementsbytagname("input"); var arr = [].slice.call(abc); }
this it:
abc.nameditem('fileuploadcontrol')
but beware that:
different browsers behave differently when there more 1 elements matching string used index (or nameditem's argument). firefox 8 behaves specified in dom 2 , dom4, returning first matching element. webkit browsers , internet explorer in case return htmlcollection , opera returns nodelist of matching elements.
from here.
this means if in markup had this:
<div id='id'>foo</div> <div id='id'>bar</div>
browsers behave differently when executing following code:
document.getelementsbytagname('div').nameditem('id')`
firefox return htmlelement, while ie return htmlcollection.
to solve inconsistencies, apply function return same object.
retelement( abc.nameditem('id') );
which this:
var retelement = function(oelem) { //firefox if (oelem instanceof window.htmlelement) return oelem; //ie , webkit if (oelem instanceof window.htmlcollection) return oelem.item(0); };
Comments
Post a Comment