Selecting Elements:

Estimated reading: 1 minute 77 views

1.getElementById

				
					var element = document.getElementById('elementId');

				
			

2.getElementsByClassName:

				
					var elements = document.getElementsByClassName('className');

				
			

3.getElementsByTagName:

				
					var elements = document.getElementsByTagName('tagName');


				
			

4.querySelector:

				
					var element = document.querySelector('selector');



				
			

5.Changing attributes:

				
					element.setAttribute('attributeName', 'attributeValue');


				
			

6.Adding CSS classes:

				
					element.classList.add('className');


				
			

7.Removing CSS classes:

				
					element.classList.remove('className');


				
			
Share this Doc

Selecting Elements:

Or copy link