DOM Manipulation

setAttribute

setAttribute

Attributes are the values written on HTML tags, such as src, alt, href, and aria-label. JavaScript can read or change them after the page loads.

setAttribute is useful when the attribute name is the thing you want to work with directly.

Your task: Select the profile image. Set its src to /avatars/mira.png and its alt text to Mira smiling.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

setAttribute

Attributes are the values written on HTML tags, such as src, alt, href, and aria-label. JavaScript can read or change them after the page loads.

setAttribute is useful when the attribute name is the thing you want to work with directly.

Your task: Select the profile image. Set its src to /avatars/mira.png and its alt text to Mira smiling.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.