I
I
IDONTSUDO2020-04-23 16:25:14
JavaScript
IDONTSUDO, 2020-04-23 16:25:14

HTMLcollection how to pull out a separate DIV?

There is such a function. I get a DIV from it with the fieled ID. And I need to change its width height depending on other divs.

function init() {
  let LeftCornerInitContent = getCoords(document.getElementById(`${structuresHTMLAndCoordinats[0].item}`));
  let RightCornerInitContent = getCoords(
    document.getElementById(`${structuresHTMLAndCoordinats[structuresHTMLAndCoordinats.length - 1].item}`)
  );

  let rootObj = document.getElementById('fieled');

  let ofsetResultOne = LeftCornerInitContent.right - RightCornerInitContent.left + 'px';
  let ofsetResultTwo = LeftCornerInitContent.bottom - RightCornerInitContent.top + 'px';
  if (rootObj && LeftCornerInitContent && RightCornerInitContent) {
    rootObj.style.width = ofsetResultOne;
    rootObj.style.height = ofsetResultTwo;
    console.log(rootObj);
  } else {
    init();
  }

  // console.log(rootObj.style.width)
}
init();


But when I receive it, I get, not only this div. And also the chilldllist of the divs nested in it.

And so this trick. Does not work.
rootObj.style.width = ofsetResultOne;
rootObj.style.height = ofsetResultTwo;


The question is, how can I get only this div without nested collections on it, or how can I change its height and width.

CODE:

PSFunction at the very end.
https://playcode.io/560144

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-04-23
@IDONTSUDO

But when I receive it, I get, not only this div. And also the chilldllist of the divs nested in it.
No, you don't. The getElementById function always returns one element if found.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question