Search code examples
javascriptjquerytampermonkey

Trying to change the style of element and click


So my script doesn't function properly. It's a simple script. What I would like it to do is simply change the style of a element. It's finding the element by the attribute "title" as you can tell.

You can also see what I've tried to do to change the style of the element but no luck. If someone can help me with a quick fix.

Here's my code:

document.onkeyup = function(e) {
if (e.which == 77) {
$("[title=#dc0000]").setAttribute("style", "background-color: #00ff00;").click(); //Change style, & click.
 console.log(""M" Pressed. Changed and clicked.") //Logs. Alerting.
}
};

Solution

  • document.onkeyup = function(e) {
        if (e.which == 77) {
            $("[title=#dc0000]").css("background-color","#00ff00;").click();
            console.log(""M" Pressed. Changed and clicked.") 
        };