Instead of using background color to determine the flip state, consider checking for the presence of the Id
attribute. Here is the updated code:
const dbclickre = document.querySelector(".reverse");
function flipped() {
if ( document.querySelector(".linkrec").getAttribute("Id") == undefined ) {
document.querySelector(".linkrec").setAttribute("Id", "flipped");
} else {
document.querySelector(".linkrec").removeAttribute("Id", "flipped")
}
}
Edit:
Why wouldn't element.style
work?
According to information on MDN Web Docs:
The style
property is used for accessing and setting the inline style of an element.
Therefore, the style
property will not function with external or embedded CSS styles.
Additionally, it is not recommended to rely on hard-coded colors as conditions, as any changes in the corresponding CSS classes could result in complete functionality failure.