You can get all the src
attributes of source
tags inside a video
tag using JavaScript by accessing the video
element and its source
child elements, and then retrieving the src
attribute of each source
element. Here's how you can do it:
index.tsx428 chars12 lines
Here, we first use document.querySelector()
to retrieve the video
element. Then, we use querySelectorAll()
to retrieve all the source
child elements of the video element. We then use Array.from()
to convert the node list of source
elements to an array, and map()
to retrieve the src
attribute of each source
element using the getAttribute()
method. Finally, we log the src attributes to the console.
gistlibby LogSnag