Home  >  Article  >  Web Front-end  >  Introduction to common methods of obtaining element instructions in js (with code)

Introduction to common methods of obtaining element instructions in js (with code)

不言
不言Original
2018-08-21 14:42:051795browse

This article brings you an introduction to the common methods of obtaining element instructions in js (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

  • Obtain through the ID of the element: getElementById(); (for a single element)

(The following instructions often obtain an array, if To obtain one of the elements, the corresponding subscript should be added at the end)

  • Obtain through the class name of the element: getElementsByClassName();

  • Get through the tag name of the element: getElementsByTagName();

  • Get through the name of the element: getElementsByName();



	
		
		
	
	
		
			文字
		
		
			文字
		
		
			文字
		
		
			文字
		
		
		
		
		
		
	

In the browser The console can display the results:

Related recommendations:

js gets php (ecshop smarty template) array element value

js specific implementation of obtaining element collection through element class name_javascript skills

The above is the detailed content of Introduction to common methods of obtaining element instructions in js (with code). 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