My goal is to display periodic table data within a single div using an onClick event, extracting the data from the li attribute itself.
Javascript snippet:
<script>
function showElement() {
var number = document.getElementById("myBtn").getAttribute("data-number");
var symbol = document.getElementById("myBtn").getAttribute("data-symbol");
var name = document.getElementById("myBtn").getAttribute("data-name");
var mass = document.getElementById("myBtn").getAttribute("data-mass");
document.getElementById("element-info").innerHTML = '<span class="atomic-number">' + number + '</span>' + '<h1>' + symbol + '</h1>' + '<p>' + name + '</p>' + '<p>' + mass + '</p>';
}
</script>
Here's the corresponding HTML code:
enter code here
You can view the layout in the following screenshot: view image description here
Any feedback or suggestions are welcome.