💻
NoVariety Documentation
  • Overview
  • ROBLOS Documentation
    • Terminal Language
    • Coding Language
  • ROBLOS Website Creator
    • AppInstaller Files
    • HTML Interpreter
    • CSS Interpreter
      • position
      • size
      • anchor-point
      • layout-order
      • text-scale
      • text-wrap
      • color
      • background-color
      • background-transparency
      • border-size
      • border-color
      • rotation
      • visible
      • content
    • LUAScript
      • download
        • commit
      • Player
      • DOM
        • Document
          • title
          • setTitle
          • getTitle
          • addEventListener
          • removeEventListener
          • dispatchEvent
          • createNode
          • querySelector
          • getElementById
          • cloneNode
        • Elements
          • getElementById
          • getElementsById
          • querySelector
          • querySelectorAll
          • appendChild
          • insertBefore
          • removeChild
          • insertAttribute
          • removeAttribute
          • cloneNode
        • Window
          • Location
            • reload
            • to
            • teleport
          • localStorage
            • setKey
            • getKey
            • deleteKey
            • getKeys
          • alert
          • input
      • delay
      • setTimeout
      • setInterval
      • clearInterval
      • MarketPlace
        • promptGamepass
        • promptProductPurchase
        • promptPurchase
        • hasGamepass
        • hasAsset
        • purchaseSuccess
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. ROBLOS Website Creator
  2. LUAScript
  3. DOM
  4. Document

addEventListener

The addEventListener() method sets up a function that will be called whenever the specified event is delivered to the target.

Returns EventId

document.addEventListener(eventName: String,callback: function): EventId

Examples

local eventid = document.addEventListener("DOMContentLoaded",function(timeTaken)
    -- DOMContentLoaded gives you the time taken to load the DOM which uses os.clock
    -- This only runs ONCE and it's when the page is first loaded.
    print("DOM Took " .. tostring(timeTaken) .. " to load!"
end)

local eventid2 = document.addEventListener("DOMContentRefreshed",function(timeTaken)
    -- DOMContentRefreshed gives you the time taken to load the DOM which uses os.clock
    -- This only runs every time you make a change using LuaScript which reloads the
    -- entire DOM
    print("DOM Took " .. tostring(timeTaken) .. " to load!"
end)
local eventid = document.addEventListener("customEvent",function(arg1)
    print("Custom Event Loaded!", arg1)
end)

document.dispatchEvent("customEvent", "test")
PreviousgetTitleNextremoveEventListener

Last updated 10 months ago

Was this helpful?