How to check if an element exists in javascript?

JavaScript 1: find element by id

// find elements by id
document.querySelectorAll('#element_id').length > 0) { 
	// Do something 
}

JavaScript 2:  find element by class

// find elements by element class
document.querySelectorAll('.element_class').length > 0) { 
	// Do something 
}