Capturing elements by tag and inserting into an array

Asked

Viewed 28 times

0

Well, I’m riding a carousel on a test project, and I came up with a question, how can I, with vanillaJS, capture certain elements by tag, and put them inside a array ? The idea would be more precisely, capture according to the position on the body of the HTML, for example capture all figure that are within a div whose father is #banners.

How can I do this by loading the page ?

  • 1

    Could add the code?

  • has no code ready, the array would be my first step, just schemed on paper even :D

  • I only have html, but it would be like the example given, I would have nothing different msm

  • 1

    Try this: var arr = Document.querySelectorAll("#banners figure");

  • Get it, more pole please, it’ll help a lot

  • perfect @Juniornunes

  • put code as answer man :D

  • 1

    All right, I’ll answer then.

Show 3 more comments

1 answer

1


You can use the document.querySelectorAll, thus:

var arr = document.querySelectorAll("#banners figure")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.