admin管理员组文章数量:1331849
I have the following code which seems to work fine in all browsers except IE8 and below.
$("table.availability").each( function() {
var siteName = $(this).parent().siblings("h2").contents().filter(function() { return this.nodeType == Node.TEXT_NODE; }).text()
alert(sitename);
});
It gets the content of an element and strips out everything contained within a child element just leaving the text of that element.
The error I get says that Node
is undefined - so I declare it at the top of the js file and then get the same message about TEXT_NODE
so I declare that. I then get the following error:
Unable to get property 'TEXT_NODE' of undefined or null reference
Can anyone help me to fix this or can anyone think of a better way to get the same result. Thanks.
I have the following code which seems to work fine in all browsers except IE8 and below.
$("table.availability").each( function() {
var siteName = $(this).parent().siblings("h2").contents().filter(function() { return this.nodeType == Node.TEXT_NODE; }).text()
alert(sitename);
});
It gets the content of an element and strips out everything contained within a child element just leaving the text of that element.
The error I get says that Node
is undefined - so I declare it at the top of the js file and then get the same message about TEXT_NODE
so I declare that. I then get the following error:
Unable to get property 'TEXT_NODE' of undefined or null reference
Can anyone help me to fix this or can anyone think of a better way to get the same result. Thanks.
Share asked Nov 14, 2012 at 11:24 TomTom 13k50 gold badges153 silver badges247 bronze badges3 Answers
Reset to default 8The TEXT_NODE
constant has a value of 3. You can just use that:
return this.nodeType === 3;
Older versions of IE just don't implement the Node
interface, but they do still follow the DOM spec and assign the correct nodeType
property values.
If you want to use the "constant", you can declare a Node
object yourself:
var Node = Node || {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3
// etc... if you might need other node types
};
For IE8 and below version node does not work, changing node
to window
worked for me.
I'm guessing that you're structure is something like this:
<h2>
text to filter
<span>other text</span>
</h2>
And you're trying to filter out the "other text" inside h2? If so - why not add another tag wrapper around the text that you need, e.g.
<h2>
<span class="text-to-filter">text to filter</span>
<span>other text</span>
</h2>
and do that:
$(this).parent().siblings("h2").find('.text-to-filter').text()
本文标签: jqueryJavascript 39Node39 undefined in IE8 and underStack Overflow
版权声明:本文标题:jquery - Javascript 'Node' undefined in IE8 and under - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742221204a2435452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论