html - What is the correct way to use custom vanilla javascript with in a AMP (ACCELERATED MOBILE PAGES) wesbite -


iv have gone through accelerated mobile pages project examples , documentation. appeared me no javascript(inline , or src) allowed. below code snippet. , heres validation error im getting.

the attribute 'src' in tag 'amphtml engine v0.js script' set invalid value

function loads_stuff(){           var $body = document.body,             $menu_trigger = $body.getelementsbyclassname('menu-trigger')[0];           if (typeof $menu_trigger !== 'undefined') {             $menu_trigger.addeventlistener('click', function() {               $body.classname = ($body.classname == 'menu-active') ? '' : 'menu-active';             });           }     } window.onload = loads_stuff; 

i understand amp lets uses <script type="application/ld+json"> inline javascript, json. need make simple mobile menu 1 click event shows , hides div.

third-party javascript isn't allowed in valid amp outside of amp-iframe. i'd recommend amp-sidebar simple hamburger menu.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -