what-is","metadata":{}}]}}]},"metadata":{"auth":{},"testAttributes":{}},"context":{"page":{"locale":"en-US","site":"Global","pageUrl":"https://aws.amazon.com/what-is/event-listener/","targetName":"Live","pageSlotId":"04e5e298-d658-4b87-98cd-ec95d1214069","organizationId":"aws-marketing","availableLocales":["\"ar-SA\"","\"de-DE\"","\"en-US\"","\"es-ES\"","\"fr-FR\"","\"id-ID\"","\"it-IT\"","\"ja-JP\"","\"ko-KR\"","\"pt-BR\"","\"ru-RU\"","\"th-TH\"","\"tr-TR\"","\"vi-VN\"","\"zh-CN\"","\"zh-TW\""]},"environment":{"stage":"prod","region":"us-east-1"},"sdkVersion":"1.0.129"},"refMap":{"manifest.js":"289765ed09","what-is-header.js":"2e0d22c000","what-is-header.rtl.css":"ccf4035484","what-is-header.css":"ce47058367","what-is-header.css.js":"004a4704e8","what-is-header.rtl.css.js":"f687973e4f"},"settings":{"templateMappings":{"category":"category","headline":"headline","primaryCTA":"primaryCTA","primaryCTAText":"primaryCTAText","primaryBreadcrumbText":"primaryBreadcrumbText","primaryBreadcrumbURL":"primaryBreadcrumbURL"}}}

event-listener","metadata":{}}]}},{"fields":{"faqQuestion":"What is the syntax of the event listener function? ","faqAnswer":"

The event listener function shares similar characteristics to other JavaScript functions. When activated, it takes the necessary action to process the event. For example, the event listener function can change displayed text, collect information from registration forms, or store data in databases.  \n

Event listener syntax \n

An event listener function follows proper JavaScript syntax, like in this next example. \n

function RespondMouseClick() { \n

            document.getElementById(\"textdisplay1\").innerHTML += \"MouseClick happened\" ; \n

        } \n

This example shows the RespondMouseClick event listener function. It’s common to write the function name to reflect the purpose of the event listener. In the function, you write codes to perform specific actions when the event occurs. In this example, the function appends the text MouseClick happened to the HTML element textdisplay1.  \n

Event handler syntax \n

Alternatively, you might use an event handler function to respond to the activated event, like in the following example.  \n

function eventHandler(event) { \n

  if (event.type === \"fullscreenchange\") { \n

console.log (“full screen toggle”); \n

  } else { \n

  console.log (“full screen error”); \n

  } \n

} \n

This allows you to manage several types of events from a specific element with one function. \n

For example, you could register an event listener to handle all types of blockchain events on event-based applications. For more information, read about building an event-based application with Amazon Managed Blockchain.","id":"seo-faq-pairs#what-is-the-syntax-of-the-event-listener-function","customSort":"2"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#event-listener","name":"event-listener","namespaceId":"seo-faq-pairs#faq-collections","description":"

event-listener","metadata":{}}]}},{"fields":{"faqQuestion":"How do you add an event listener?","faqAnswer":"

An event listener will only be activated after you add it to the respective JavaScript element. To do that, you can use syntax like this: \n