"Object Required" error in IE from $.map over array of dom elements
For
$.m开发者_如何学JAVAap(holder[i], function (elem, index) {
if (elem.nodeType === 1) {
var attr = "";
if (typeof elem.attributes !== 'undefined') {
attr = ' ' + elem.attributes[0].name + '=' + '"' + elem.attributes[0].nodeValue + '"';
}
return '<' + elem.nodeName + attr + '>' + elem.textContent + '</' + elem.nodeName + '>';
} else if (elem.nodeType === 3) {
return elem.textContent
}
});
Where holder[i] is an array of nodes gotten from iterating over XML with
$('[btn-label="' + title + '"] flashtext', myXML).each(function(){ holder.push($(this).contents().get()); });
why could I be getting the error "Object Required" in IE7? Says the problem is here:
if (typeof elem.attributes !== 'undefined' )
This is because the attributes property of a jQuery object will never be undefined, but will be null
(e.g. a text node), an empty array (for a tag with no attributes, e.g. <strong>
) or a array of associative arrays.
精彩评论