Reputation: 1
I am trying to change the 1 to x. I am getting an error. Perhaps there is an easier way.
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="container">
<div id="id1" onclick="changeText(this.id); this.onclick=null;">1</div>
</div>
<script src="javascript.js"></script>
</body>
</html>
Javascript:
function changeText(selectedId) {
document.getElementById("selectedId").innerHTML = "x"
};
Upvotes: 0
Views: 360
Reputation: 2368
You're trying to get an element that has id="selectedId"
& there isn't one.
Remove the quotation marks in your JavaScript so it is just:
document.getElementById(selectedId).innerHTML = "x"
Upvotes: 1