How to get element by id inside a block returned by getElementById ()

0

Next ...

I want to find an element (form) that is inside a block. I use .getElementById(); to get this block.

After getting the block, I want to find the form that is in this block so that I can include an element before that form. I'm trying this way, and so far, I have not been able to:

javascript

var boardElem = document.getElementById('board-01');
var formEl = boardElem.children('#formNewTask');

It did not work ... Then I tried to use it too:

var formEl = boardElem.getElementById('formNewTask');

And the error generated is this: Uncaught TypeError: boardElem.getElementById is not a function

I'm used to jQuery. But I'm developing a project without using the framework. Any light?

Thank you!

    
asked by anonymous 22.03.2016 / 22:04

1 answer

1

I was able to ...

I solved the problem. I needed a selector to find the element. I've tried children , getElementById , getElementByTagName , ...

And I was not remembering the main ... querySelector .

It worked like this:

var boardElem = document.getElementById('board-01');
var formEl = boardElem.querySelector('form');
boardElem.insertBefore(novoElemento, formEl);

Since I will only have 1 form within board , I will not use ID. And yes the tag name as parameter in the selector. I was suffering from it!

    
22.03.2016 / 22:18