I'm trying to get a button disabled when I press another button, but it's not working.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2023.11.1/core.css" />
<script type="module" src="https://pyscript.net/releases/2023.11.1/core.js"></script>
</head>
<body>
<div>
<button id="run" py-click="colorChange">NO CLICK</button>
<button id="run2" py-click="disabled">CLICK</button>
</div>
<style>
#run{ background-color: rgb(61, 139, 130)}
#run2{ background-color: rgb(179, 28, 65)}
</style>
<py-script>
from js import document
runButton=document.getElementById("run")
def colorChange(event):
runButton.setAttribute("style", "background-color:red")
def disabled(event):
runButton.setAttribute("style", "disabled:True")
</py-script>
</body>
</html>
I would greatly appreciate any help. Thank you so much.
You're currently setting a CSS rule called "disabled" to
True
. You want to be setting the attributedisabled
to True:Related, when you want to re-enable that button, use the
removeAttribute
function, instead of setting disabled to False.