Home » Jquery » javascript – How can I manipulate the child node of this element?-Exceptionshub

javascript – How can I manipulate the child node of this element?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

My Chrome Extension needs to change the size of the child node to the following.

Notice how the ‘width’ is set for the parent DIV…my Chrome Extension did that.

I can show the following element in the console by:

var divContainer2 = $(divContainer)[0];
console.log('Now divContainer is: ', divContainer2); 

The element shown in the console by the above (just the start of it, but showing the parent/child relationship):

<div class="v7wOcf ZGnOx" style="margin-top: 80px; width: 1207px;">
        <div jscontroller="Zptowf" jsaction="R6jwd:hKrBwc;c96EGd:v8OFqc;QmtCl:.CLIENT;qVp5ue:.CLIENT;AE9bOd:.CLIENT;MmB7ud:.CLIENT;zkkUY:.CLIENT;lyIVcf:.CLIENT;wuANJc:.CLIENT;voP7ud:.CLIENT" jsmodel="PuTOgd IaLzN tZ2gdc dSSknb PTCFbe ephE9e lkzLle OqPTdc nQnzVc VeaFK uArcre" data-without-stream-item-materials="" class="DReKqd" data-submission-id="1" data-view-id="46"><div jscontroller="cs6ocd" jsaction="rcuQ6b:npT2md;KDsQaf:Qp7hp;qFgNIJf-Wvd9Cc Yiql6e iTy5c editable" tabindex="0" role="textbox" aria-required="true" aria-multiline="true"

I want to apply similar styling to the child (the DIV on the second line…with the ‘jscontroller’).

To make things very explicit I’ve tried:

var divContainer3 = divContainer2[0];
var divContainer3 = divContainer2.children[0]; 

And others…

What am I missing? Why can’t I grab the childnode of the object I can so clearly push to console and manipulate?

Thank you for any help/direction/guidance…

How to&Answer:

The issue wasn’t syntax…it was dynamic content loading…and so when I was grabbing the childNodes (or trying to) the element didn’t exist.

What continues to be confusing for me is that the CONSOLE will show an element called out in console.log even though it didn’t exist at the time the particular line of code ran.

So I could SEE the element, and it’s nodes/length, in the console but the very next line of code that simply logged the length would come up zero. Because when the length code ran the element didn’t really exist.

I added a little ‘wait’ routine to make sure the thing is there before I try to manipulate it.