Call function from another jQuery
jquery
Solution
Add another function that is used by both methods:
$(document).keydown(function(e){
if (e.keyCode == 37) {
move("left");
}
});
$(".direction").click(function() {
move($(this).text());
});
function move(newDirection)
{
var direction = newDirection;
}
Problem
``` $(document).keydown(function(e){ if (e.keyCode == 37) { return false; } }); $(".direction").click(function() { var direction = $(this).text(); ``` When I click on a button with .direction class the second function above is called. When the left key is pressed I want to call the `$(".direction").click(function() {` But with a value (Instead of the var direction = $(this).text(); part) It would be var direction = value passed to function; How can I do that?