search
HomeWeb Front-endJS TutorialSummary of some commonly used attributes in DOM operations_javascript skills

1.DOM: Document Object Model DOM (Document Object Model) defines a standard method for accessing and processing HTML documents. DOM presents HTML documents as a tree structure (node ​​tree) with elements, attributes, and text.

2. Some commonly used attributes of DOM

 2.1 Get elements by ID

(1) Grammar:

Copy code The code is as follows:

document.getElementById("id");

(2) Function: ID is a person’s ID card. We can find the tag by looking for its ID, and then perform corresponding operations.

(3) Note: Don’t forget to write the document!

 2.2 innerHTML attribute

(1) Grammar:

Copy code The code is as follows:

Obgect.innerHTML="Hello World"

(2) Function: Mainly to obtain or replace the content in the tag

 (3) Example:

Copy code The code is as follows:





innerHTML


javascript


JavaScript is a simple object-based, event-driven scripting language. It is embedded in HTML documents and is interpreted and executed by the browser. It produces dynamic display effects on web pages and implements interactive functions with users.





 (4) Note: Object is the element object obtained, such as the element obtained through document.getElementById("ID").

 2.3 Change HTML style

(1) Grammar:

Copy code The code is as follows:

Object.style.property

(2) Function: Used to modify HTML style

 (3) Example:

Copy code The code is as follows:


I love JavaScript


JavaScript enables web pages to display dynamic effects and implement interactive functions with users.




(4) Note: There are many styles of property, such as color, height, etc., which can be modified using this method. Don’t forget to add a semicolon after the property.

 2.4 Showing and hiding (display attribute)

(1) Grammar:

Object.style.display=value
(2) Function: Showing and hiding are often seen on web pages, which is achieved using the display attribute

 (3) Example:

Copy code The code is as follows:




(4) Note: The value of value is none and block, where none means not to display content, and block means to display content

 

2.5 className attribute

(1) Grammar:

Object.className=classname


(2) Function: 1. Get the class attribute of the element; 2. Specify a css style for an element in the web page to change the appearance of the element

 (3) Example:


className attribute



JavaScript enables web pages to display dynamic effects and implement interactive functions with users.



JavaScript enables web pages to display dynamic effects and implement interactive functions with users.







The above is the entire content of this article, I hope you all like it.
Statement
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
PHP编程中有哪些常见的Behat操作?PHP编程中有哪些常见的Behat操作?Jun 12, 2023 am 08:19 AM

PHP编程中有哪些常见的Behat操作?Behat是一个行为驱动开发(BDD)工具,允许测试人员和开发人员在自然语言中撰写测试用例,并将这些用例转化为可执行的代码。它支持PHP语言,并提供了丰富的库和功能,可以实现多种常见的测试操作。下面列举了PHP编程中常见的Behat操作。前置条件(Background)在编写测试用例时,有时候会有一些公共的前置条件需要

Vue3获取DOM节点的方式有哪些Vue3获取DOM节点的方式有哪些May 11, 2023 pm 04:55 PM

1.原生js获取DOM节点:document.querySelector(选择器)document.getElementById(id选择器)document.getElementsByClassName(class选择器)....2.vue2中获取当前组件的实例对象:因为每个vue的组件实例上,都包含一个$refs对象,里面存储着对应的DOM元素或组件的引用。所以在默认情况下,组件的$refs指向一个空对象。可以先在组件上加上ref="名字",然后通过this.$refs.

PHP中的DOM操作指南PHP中的DOM操作指南May 21, 2023 pm 04:01 PM

在网页开发中,DOM(DocumentObjectModel)是一个非常重要的概念。它可以让开发者轻松地对一个网页的HTML或XML文档进行修改和操作,比如添加、删除、修改元素等。而PHP中内置的DOM操作库也为开发者提供了丰富的功能,本文将介绍PHP中的DOM操作指南,希望可以帮助到大家。DOM的基本概念DOM是一个跨平台、独立于语言的API,它可以将

vue dom是什么意思啊vue dom是什么意思啊Dec 20, 2022 pm 08:41 PM

dom是一种文档对象模型,同时也是用于html编程的接口,通过dom来操作页面中的元素。DOM是HTML文档的内存中对象表示,它提供了使用JavaScript与网页交互的方式。DOM是节点的层次结构(或树),其中document节点作为根。

vue3中ref绑定dom或组件失败的原因是什么及怎么解决vue3中ref绑定dom或组件失败的原因是什么及怎么解决May 12, 2023 pm 01:28 PM

vue3ref绑定dom或者组件失败原因分析场景描述在vue3中经常用到使用ref绑定组件或者dom元素的情况,很多时候,明明使用ref绑定了相关组件,但是经常ref绑定失败的情况。ref绑定失败情况举例ref绑定失败的绝大多数情况是,在ref和组件绑定的时候,该组件还未渲染,所以绑定失败。或者组件刚开始未渲染,ref未绑定,当组件开始渲染,ref也开始绑定,但是ref和组件并未绑定完成,这个时候使用组件相关的方法就会出现问题。ref绑定的组件使用了v-if,或者他的父组件使用了v-if导致页面

dom和bom对象有哪些dom和bom对象有哪些Nov 13, 2023 am 10:52 AM

dom和bom对象有:1、“document”、“element”、“Node”、“Event”和“Window”等5种DOM对象;2、“window”、“navigator”、“location”、“history”和“screen”等5种BOM对象。

bom和dom有什么区别bom和dom有什么区别Nov 13, 2023 pm 03:23 PM

bom和dom在作用和功能、与JavaScript的关系、相互依赖性、不同浏览器的兼容性和安全性考虑等方面都有区别。详细介绍:1、作用和功能,BOM的主要作用是操作浏览器窗口,它提供了浏览器窗口的直接访问和控制,而DOM的主要作用则是将网页文档转换为一个对象树,允许开发者通过这个对象树来获取和修改网页的元素和内容;2、与JavaScript的关系等等。

PHP编程中有哪些常见的OAuth操作?PHP编程中有哪些常见的OAuth操作?Jun 12, 2023 am 08:48 AM

OAuth(开放授权)是一种用于授权访问控制的标准化协议。在Web开发中,使用OAuth可以帮助应用程序安全地从第三方平台中获取用户数据或资源。而在PHP编程中,OAuth操作也被广泛应用。本文将介绍PHP编程中的常见OAuth操作。OAuth1.0a授权OAuth1.0a授权是OAuth中最早出现的授权方式,也是最复杂的一种授权方式。在PHP编程中,O

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),