javascriptnodelisthtmlcollection

how to get the dynamic html element id value using HtmlCollections or Nodelist


i was making the dynamic element by using innerhtml, but i did not get the element id dynamically.

var videoWrap = document.getElementsByClassName('videoWrap');
   console.log(videoWrap)

//console value

HTMLCollection(1)
0: div#cardvideo_localstream.p-1.position-relative.videowrap
cardvideo_localstream: div#cardvideo_localstream.p-1.position-relative.videowrap
length: 1
[[Prototype]]: HTMLCollection
item: ƒ item()
length: (...)
namedItem: ƒ namedItem()
constructor: ƒ HTMLCollection()
Symbol(Symbol.iterator): ƒ values()
Symbol(Symbol.toStringTag): "HTMLCollection"
get length: ƒ length()
[[Prototype]]: Object

i want to get the id value -> #cardvideo_localstream


Solution

  • There are two ways:

    But in both case the format/structure should be fix otherwise it'll break.