Implement a method getElementsByStyle()
that finds DOM elements that are rendered by the browser using the specified style. It is similar to Element.getElementsByClassName()
but with some differences:
getElementsByStyle(document.body, 'font-size', '12px')
.Element.getElementsByClassName()
, only descendants of the element argument are searched, not the element itself.Element
s, instead of an HTMLCollection
of Element
s.Do not use document.querySelectorAll()
which will make the problem trivial otherwise. You will not be allowed to use it during real interviews.
const doc = new DOMParser().parseFromString(`<div><span style="font-size: 12px">Span</span><p style="font-size: 12px">Paragraph</p><blockquote style="font-size: 14px">Blockquote</blockquote></div>`,'text/html',);getElementsByStyle(doc.body, 'font-size', '12px');// [span, p] <-- This is an array of elements.
You might find the Window.getComputedStyle()
method helpful.
Implement a method getElementsByStyle()
that finds DOM elements that are rendered by the browser using the specified style. It is similar to Element.getElementsByClassName()
but with some differences:
getElementsByStyle(document.body, 'font-size', '12px')
.Element.getElementsByClassName()
, only descendants of the element argument are searched, not the element itself.Element
s, instead of an HTMLCollection
of Element
s.Do not use document.querySelectorAll()
which will make the problem trivial otherwise. You will not be allowed to use it during real interviews.
const doc = new DOMParser().parseFromString(`<div><span style="font-size: 12px">Span</span><p style="font-size: 12px">Paragraph</p><blockquote style="font-size: 14px">Blockquote</blockquote></div>`,'text/html',);getElementsByStyle(doc.body, 'font-size', '12px');// [span, p] <-- This is an array of elements.
You might find the Window.getComputedStyle()
method helpful.
console.log()
aparecerão aqui.