0

I am curios to know if something like these would work in javascript, or if there is a way to do it. Basically, i want to call a function onclick of one object and the same function onmouseover of another object.

document.getElementById("one").onmouseover || document.getElementById("two").onclick= function() {myFunction()};

is this possible

1

1 Answer 1

4

When you assign a value to something, the expression evaluates as that value.

foo = bar = 1;

Your code would be clearer if you just used named functions though.

document.getElementById("one").addEventListener("mouseover", myFunction);
document.getElementById("two").addEventListener("click",     myFunction);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.