i want to change script data using javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<button id="loadData">Check</button>
<button id="change">Change Data</button>
<script id="datas">
data = {
key: "ABCDEFG",
balance: "100",
}; // change this data using id
</script>
<script>
// loadDataButton = document.getElementById("loadData");
document.getElementById("loadData").addEventListener("click", function () {
alert(data.key);
});
document.getElementById("change").addEventListener("click", function () {
document.getElementById("datas").innerHTML = `data = {
key: "BCSD123",
balance: "200",
};`; // changed new data but till giving me key ABCDEFG
alert(data.key);
});
</script>
</body>
</html>
this method change only for show but i click on check button than giving me old data .. this problem i am facing . i want data key after change script tag data BCSD123
2
Answers
There’s no need to modify the contents of a
<script>
tag.data
‘s key values using a new Proxydata
object:I guess you want to change data’s value through dynamics, you can change the value of variable in the callback function.