Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is an error in js file,line 3 that say:


What I have tried:

(function() {
	var triggerBttn = document.getElementById( 'trigger-overlay' ),
		overlay = document.querySelector( 'div.overlay' ),
		closeBttn = overlay.querySelector( 'button.overlay-close' );
		transEndEventNames = {
			'WebkitTransition': 'webkitTransitionEnd',
			'MozTransition': 'transitionend',
			'OTransition': 'oTransitionEnd',
			'msTransition': 'MSTransitionEnd',
			'transition': 'transitionend'
		},
		transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
		support = { transitions : Modernizr.csstransitions };
		s = Snap( overlay.querySelector( 'svg' ) ), 
		path = s.select( 'path' ),
		pathConfig = {
			from : path.attr( 'd' ),
			to : overlay.getAttribute( 'data-path-to' )
		};

	function toggleOverlay() {
		if( classie.has( overlay, 'open' ) ) {
			classie.remove( overlay, 'open' );
			classie.add( overlay, 'close' );
			
			var onEndTransitionFn = function( ev ) {
				classie.remove( overlay, 'close' );
			};
			
			path.animate( { 'path' : pathConfig.from }, 400, mina.linear, onEndTransitionFn );
		}
		else if( !classie.has( overlay, 'close' ) ) {
			classie.add( overlay, 'open' );
			path.animate( { 'path' : pathConfig.to }, 400, mina.linear );
		}
	}

	triggerBttn.addEventListener( 'click', toggleOverlay );
	closeBttn.addEventListener( 'click', toggleOverlay );
})();
Posted
Updated 11-Oct-17 0:09am

1 solution

Make sure the DOM contains the div element with the class overlay

Quote:
Uncaught typeerror: cannot read property 'queryselector' of null

You will get this error, when you try to access the members of an object which is null, Validate for null values before accessing the members

overlay = document.querySelector('div.overlay'),
          if(overlay != null){  // validate for null value
              closeBttn = overlay.querySelector('button.overlay-close');
 
Share this answer
 
Comments
Fuad Manaye 8-Oct-21 3:56am    
Uncaught TypeError: Cannot read properties of null (reading 'querySelector' how to fix this statement when am coding this line of code
const wrapper = document.querySelector(".wrapper"),
searchInput = wrapper.querySelector("input"),
Karthik_Mahalingam 8-Oct-21 4:34am    

const wrapper = document.querySelector(".wrapper"),
if(wrapper!= null) {
searchInput = wrapper.querySelector("input")
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900