Exercise 8: Set Multiple Attributes
Problem Statement
Function `setAttributes(el, attrs)` banao jo element pe multiple attributes set kare.
Example: setAttributes(imgEl, {src: "image.jpg", alt: "Image"})
Sample Output:
setAttributes(imgEl, {src: "image.jpg", alt: "Image"})
// Sets both src and alt attributesSolution
const setAttributes = (el, attrs) => {
Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
};Explanation
Overall Goal:
- Element pe multiple attributes ek saath set karna.
Real world:
- Dynamic attributes: batch updates.
- Element configuration: attribute setup.