0

Naturally I tried:

function show() {
   this.parent.childNodes[1].childNodes[1].visibility = 'hidden';
}

But debugger says that parent has no property children. What I'm doing wrong guys? And I can't use jQuery, I'm on hosted webserver.

10
  • 2
    I don't see "children" anywhere in the code, and you certainly can use jQuery regardless of your hosting. Commented Sep 21, 2015 at 18:02
  • By children of parent, do you mean siblings? Commented Sep 21, 2015 at 18:03
  • 3
    please, put the piece of html code you are trying to reach the children, to allow us help you. Commented Sep 21, 2015 at 18:03
  • Please give us some html and any additional javascript you're using. I can't really tell you anything with what you've given us. Commented Sep 21, 2015 at 18:04
  • What is this supposed to be? Generally it's the window, which I really doubt you are meaning to use. Commented Sep 21, 2015 at 18:08

3 Answers 3

1

You need to use parentNode for raw javascript, .parent() is jquery. So in your case:

function show() {
   this.parentNode.childNodes[1].childNodes[1].visibility = 'hidden';
}
Sign up to request clarification or add additional context in comments.

1 Comment

That's right, but that's not the root of my problem. I answered myself (got hasty with that question)
1

Well, I got hasty with this one. Parent was not node element, so it had no children. And 'this' had no parentNode property. What works is:

function show(node) {
    node.parentNode.childNodes[1].childNodes[1].style.visibility = 'hidden';
}

and

<a class="hider" onclick="show(this)">Test</a>

Naturally to other people indexes in childNodes list are irrelevant. But for me they work, but certainly it is not cleaver on nice solution.

Comments

0

Your 'this' seems to be the global scope. So 'this' points to window, which has no parent node.

1 Comment

True, I had posted answer to my own question cause I got hasty with asking one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.