What are the methods of document in js

下次还敢
Release: 2024-05-10 04:27:19
Original
1203 people have browsed it

JavaScript document object methods provide a series of methods for interacting with web documents, including: finding and returning elements (getElementById, getElementsByClassName, getElementsByTagName) creating elements and text nodes (createElement, createTextNode) manipulating the DOM structure (appendChild, insertBefore, removeChild, replaceChild) set and get style attributes (setAttribute, removeAttribute, getStyle

What are the methods of document in js

##JavaScript document object methods## The #JavaScript Document Object Model (DOM) provides a set of methods for interacting with web documents. These methods allow developers to manipulate document structure, style, and content.

Core Methods

    getElementById(id)
  • : Find and return the element by its id
  • getElementsByClassName(className)
  • : Find and return the element by its class name. Returns a set of elements.
  • getElementsByTagName(tagName)
  • : Finds and returns a set of elements by their tag name.
  • createElement(tagName)
  • : Create a new element.
  • createTextNode(text)
  • : Create a new text node.
  • appendChild(child)
  • : Append a child. Node is added to the end of the parent node.
  • insertBefore(newNode, referenceNode)
  • : Insert a new node before the specified reference node
  • removeChild(child).
  • : Remove a child node from the parent node.
  • replaceChild(newChild, oldChild)
  • : Replace an existing node with a new node.#Style methods

##setAttribute(attributeName, value): Set the specified attribute of the element

    removeAttribute(attributeName).
  • : Delete the specified attribute of the element.
  • getStyle(propertyName)
  • : Get the specified style attribute of the element.
  • setStyle(propertyName, value)
  • : Set the specified style attribute of the element.
  • Content methods

innerHTML: Gets or sets the HTML content of the element.

    innerText
  • : Gets or sets the text content of the element.
  • Event methods

addEventListener(eventName, eventHandler): Add an event handler to the element.

    removeEventListener(eventName, eventHandler)
  • : Remove an event handler from the element.
  • Other methods

cloneNode(deep): Clone an element, you can choose whether to clone the child node.

    write(text)
  • : Write text to the document.
  • close()
  • : Close the document stream.

The above is the detailed content of What are the methods of document in js. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!