How JavaScript can change HTML attribute values

Javascript / Fundamentals of Javascript

426

Program:

<!DOCTYPE html>
<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p>JavaScript can change HTML attribute values.</p>

<p>In this case JavaScript changes the value of the src (source) attribute of an image.</p>

<button onclick="document.getElementById('myImage').src='colorCar.png'">Colorful Car</button>

<img id="myImage" src="colorCar.png" style="width:100px">

<button onclick="document.getElementById('myImage').src='blackCar.png'">Black and White Car</button>

</body>
</html>

Output:

Run above code

Explanation:

no

This Particular section is dedicated to Programs only. If you want learn more about Javascript. Then you can visit below links to get more depth on this subject.