Home Web Front-end Vue.js Document properties and methods of JS

Document properties and methods of JS

Mar 14, 2024 am 10:47 AM
js document css selector

In JavaScript, the document object is a very important global object, which represents the entire HTML document. You can access and modify the content and structure of an HTML document through the document object. The following are some common document properties and methods:

Properties

1.document.title: Get or set The title of the document, usually displayed in the browser's title bar or tab.

javascript

document.title = "新的页面标题";
Copy after login

2. document.URL: Get the complete URL of the document.

javascript

console.log(document.URL);
Copy after login

3. document.documentElement: Get the root element of the document, usually the element.

javascript

console.log(document.documentElement);
Copy after login

4. document.body: Get the element of the document.

javascript

console.log(document.body);
Copy after login

5. document.head: Get the element of the document.

javascript

console.log(document.head);
Copy after login

6. document.referrer: Get the URL of the previous page that navigates to the current page.

javascript

console.log(document.referrer);
Copy after login

Method

1.document.getElementById (id): Get the element based on the specified id.

javascript

var element = document.getElementById("myElementId");
Copy after login

2. document.getElementsByClassName(className): Get the element collection based on the specified class name.

javascript

var elements = document.getElementsByClassName("myClassName");
Copy after login

3. document.getElementsByTagName(tagName): Get the element collection based on the specified tag name.

javascript

var elements = document.getElementsByTagName("div");
Copy after login

4. document.querySelector(selector): Returns the first Element in the document that matches the specified CSS selector.

javascript

var element = document.querySelector(".myClass");
Copy after login

5. document.querySelectorAll(selector): Returns a NodeList of all Element elements in the document that match the specified CSS selector ( still).

javascript

var elements = document.querySelectorAll(".myClass");
Copy after login

6. document.createElement(tagName): Create a new element.

javascript

var newElement = document.createElement("div");
Copy after login

7. document.createTextNode(text): Create a new text node.

javascript

var textNode = document.createTextNode("Hello, world!");
Copy after login

8. document.appendChild(node): Append a child node to an element of the document.

javascript

someElement.appendChild(newElement);
Copy after login

9. document.removeChild(node): Remove a child node from the document.

javascript

someElement.removeChild(childElement);
Copy after login

9. document.write(content): Write HTML expression or JavaScript code to the document.

javascript

document.write("<p>这是一个段落。</p>");
Copy after login

This is just some of the properties and methods of the document object. In fact, the document object provides many other functions and methods for handling the content and structure of HTML documents. You can learn more by consulting the relevant JavaScript documentation or tutorials.

The above is the detailed content of Document properties and methods of JS. For more information, please follow other related articles on the PHP Chinese website!

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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to resize HTML textbox How to resize HTML textbox Feb 20, 2024 am 10:03 AM

Setting the size of HTML text boxes is a very common operation in front-end development. This article explains how to set the size of a text box and provides specific code examples. In HTML, you can use CSS to set the size of a text box. The specific code is as follows: input[type="text&quot

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

How to adjust a WordPress theme to avoid misaligned display How to adjust a WordPress theme to avoid misaligned display Mar 05, 2024 pm 02:03 PM

How to adjust WordPress themes to avoid misaligned display requires specific code examples. As a powerful CMS system, WordPress is loved by many website developers and webmasters. However, when using WordPress to create a website, you often encounter the problem of theme misalignment, which affects the user experience and page beauty. Therefore, it is very important to properly adjust your WordPress theme to avoid misaligned display. This article will introduce how to adjust the theme through specific code examples.

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

GTA 6 document gives a detailed overview of all leaks GTA 6 document gives a detailed overview of all leaks Sep 08, 2024 am 06:37 AM

On September 3, version 1.5 of the Grand Theft Auto VI document which provides a detailed overview of everything that is known about the game to date. The updated version of the document was announced in a trailer published on X (formerly Twitter).??

The AI ​​era of JS is here! The AI ​​era of JS is here! Apr 08, 2024 am 09:10 AM

Introduction to JS-Torch JS-Torch is a deep learning JavaScript library whose syntax is very similar to PyTorch. It contains a fully functional tensor object (can be used with tracked gradients), deep learning layers and functions, and an automatic differentiation engine. JS-Torch is suitable for deep learning research in JavaScript and provides many convenient tools and functions to accelerate deep learning development. Image PyTorch is an open source deep learning framework developed and maintained by Meta's research team. It provides a rich set of tools and libraries for building and training neural network models. PyTorch is designed to be simple, flexible and easy to use, and its dynamic computation graph features make

See all articles