plain javascript code to highlight an html element

element.style.backgroundColor = "#FDFF47";

#FDFF47 is a nice shade of yellow that seems perfect for highlighting.

Edit for clarification: You're over-complicating things. If you ever want to restore the previous background color, just store element.style.backgroundColor and access it later.



If for some reason you need to use javascript here is function that temporary highlits element background

function highlight(element) {
    let defaultBG = element.style.backgroundColor;
    let defaultTransition = element.style.transition;

    element.style.transition = "background 1s";
    element.style.backgroundColor = "#FDFF47";

    setTimeout(function()
    {
        element.style.backgroundColor = defaultBG;
        setTimeout(function() {
            element.style.transition = defaultTransition;
        }, 1000);
    }, 1000);
}

If you're debugging in a browser that supports the CSS outline, one simple solution is this:

myElement.style.outline = '#f00 solid 2px';

Old post, but worth adding since it shows up in searches on the topic. A simple way to achieve a highlighting effect is:

myElement.style.filter = "brightness(125%)";