Why does the onclick handler below trigger an "elem.parentNode is not a function" error?
<html>
<head>
<script type="text/javascript">
function getParent(elem) {
var parent = elem.parentNode();
}
</script>
</head>
<body>
<div style="border: solid black 2px">
<span onclick="getParent(this)">hello</span>
</div>
</body>
</html>
Why does the onclick handler below trigger an "elem.parentNode is not a function" error?
<html>
<head>
<script type="text/javascript">
function getParent(elem) {
var parent = elem.parentNode();
}
</script>
</head>
<body>
<div style="border: solid black 2px">
<span onclick="getParent(this)">hello</span>
</div>
</body>
</html>
Share
Improve this question
asked Feb 19, 2009 at 22:13
mikemike
49.2k45 gold badges104 silver badges117 bronze badges
4
- 1 That's got to be the fastest 9 responses ever! – Russ Cam Commented Feb 19, 2009 at 22:19
- Obviously I posted before I saw Paolo's response e up. Why 7 other people would post the same answer shortly after... I dunno. – Sean Bright Commented Feb 19, 2009 at 22:21
- I didn't get the New answers alert while I was writing my answer – Russ Cam Commented Feb 19, 2009 at 22:23
- The SO heartbeat thing that checks for new answers is flaky these days. – Crescent Fresh Commented Feb 19, 2009 at 22:26
7 Answers
Reset to default 7Your problem is that parentNode is not a function. Try removing the ()
.
parentNode is a property, not a function.
var parent = element.parentNode;
Because parentNode
is not a function? Try elem.parentNode
without the parenthesis.
it should be
function getParent(elem) {
var parent = elem.parentNode;
}
It's not a function. It's a property. Lose the parentheses.
var parent = elem.parentNode;
parentNode is a property not a function. Drop the () and it should work.
parentNode isn't a function, it's a property.