Home  >  Article  >  Web Front-end  >  How to use getElementsByClassName()? Summary of getElementsByClassName() instance usage

How to use getElementsByClassName()? Summary of getElementsByClassName() instance usage

巴扎黑
巴扎黑Original
2017-06-15 11:46:129034browse

Earlier I introduced some newly added selectors in HTML5, namely querySelector(), querySelectorAll() and getElementsByClassName(). These three have their own unique functions. If necessary, you can read the relevant content in HTML5 actual combat and analysis. Today I will introduce to you the classList attribute.

What exactly does the classList attribute do? Let’s leave classList alone for now. We consider such a question, how do we delete one of the category names of the elements of multiple categories? Dream Dragon's strong brain finally thinks of a implementation method.

will have a class name Li, Meng, and Long, and the category name meng in the three categories is deleted.

code is as follows

HTML代码
<p class="li meng long">梦龙小站</p>  
JavaScript代码
//获取要删除类名meng的p
var

# 1. HTML5 actual combat and analysis of classList attributes

How to use getElementsByClassName()? Summary of getElementsByClassName() instance usage

##:

# Previously introduced some selection device related to HTML5, which are querySelector (), querySelectorall () and GetelementsByClassName ( ). These three have their own unique functions. If necessary, you can read the relevant content in Html5 actual combat and analysis. Today I will introduce to you the classList attribute.

2. HTML5 actual combat and analysis CSS selector -GetelementsByClassName () method

How to use getElementsByClassName()? Summary of getElementsByClassName() instance usage

Introduction:

## stequselector () method and querySelectOlLLL () method have been introduced in the previous few. No Do you know how well everyone understands?

Let’s review here. The querySelector() method returns the first element that matches the passed CSS selector; the querySelectorAll() method Returns all elements that match the passed CSS selector and is a NodeList object.

After a brief review, let me share a new method-getElementsByClassName() method.

[Related Q & A recommendation]:

Javascript -How to get GetelementsByClassName () arrays?

javascript -Why can't the following code be replaced with Class

#

The above is the detailed content of How to use getElementsByClassName()? Summary of getElementsByClassName() instance usage. For more information, please follow other related articles on the PHP Chinese website!

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