The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical…