Dưới đây là mã để truyền event object từ hàm này sang hàm khác trong JavaScript.
Ví dụ
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>Truyền event object từ hàm này sang hàm khác trong JavaScript</h1> <button class="Btn" onclick="changeFont(event)">CLICK HERE</button> <h3>Nhấn nút trên để thay đổi font size và color của nó</h3> <script> function changeFont(event) { event.target.style.fontSize = "32px"; changeColor(event); } function changeColor(event) { event.target.style.color = "red"; } </script> </body> </html>
Kết quả
Mã trên sẽ tạo ra kết quả sau:

Khi nhấn nút 'CLICK HERE':
