The toggleAttribute of Element for JS if force is not given, "toggles" qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName.
Returns true if qualifiedName is now present; otherwise false.
element.toggleAttribute(qualifiedName [, force])
<!doctype html>
<html>
<body>
<my-element class="myclass" id="myid" title="mytitle"></my-element>
<output></output>
<script>
const element = document.querySelector("my-element");
const qualifiedName = "value";
element.toggleAttribute(qualifiedName);
document.querySelector("output").innerHTML = element.getAttributeNames();
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<my-element class="myclass" id="myid" title="mytitle"></my-element>
<output></output>
<script>
const element = document.querySelector("my-element");
const qualifiedName = "id";
const force = false;
element.toggleAttribute(qualifiedName, force);
document.querySelector("output").innerHTML = element.getAttributeNames();
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<my-element class="myclass" id="myid" title="mytitle"></my-element>
<output></output>
<script>
const element = document.querySelector("my-element");
const qualifiedName = "id";
const force = true;
element.toggleAttribute(qualifiedName, force);
document.querySelector("output").innerHTML = element.getAttributeNames();
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<my-element class="myclass" id="myid" title="mytitle"></my-element>
<output></output>
<script>
const element = document.querySelector("my-element");
const qualifiedName = "id";
document.querySelector("output").innerHTML = element.toggleAttribute(qualifiedName);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<my-element class="myclass" id="myid" title="mytitle"></my-element>
<output></output>
<script>
const element = document.querySelector("my-element");
const qualifiedName = "value";
document.querySelector("output").innerHTML = element.toggleAttribute(qualifiedName);
</script>
</body>
</html>