Complete the code to select an element in Inspect mode.
element = document.querySelector('[1]')
In Inspect mode, selecting an element by its ID uses the '#' prefix. '#button' selects the element with ID 'button'.
Complete the code to get the width of the selected element in Inspect mode.
width = element.getBoundingClientRect().[1]The getBoundingClientRect() method returns the size of an element and its position. To get the width, use the width property.
Fix the error in the code to get the background color of the element in Inspect mode.
bgColor = window.getComputedStyle(element).[1]('background-color')
The correct method to get a CSS property value is getPropertyValue. Other options are invalid and cause errors.
Fill both blanks to create a function that returns the height and width of an element in Inspect mode.
function getSize(element) {
return { height: element.getBoundingClientRect().[1], width: element.getBoundingClientRect().[2] };
}The getBoundingClientRect() method returns an object with properties including height and width. These are used to get the element's size.
Fill all three blanks to write code that gets the font size, font weight, and color of an element in Inspect mode.
const style = window.getComputedStyle(element); const fontSize = style.[1]('font-size'); const fontWeight = style.[2]('font-weight'); const color = style.[3]('color');
The method getPropertyValue is used to get any CSS property value. It works for 'font-size', 'font-weight', and 'color'.