Since you already loading JQuery, add the following $('document')
:
(function($) {
$(window).load(function() { //lets wait for all to be loaded
alert("Accordion script loaded");
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
}
}
});
})(jQuery);
looks like document.getElementsByClassName("accordion");
its returning NULL
and you are trying to set the style
property of it, this due to the script running too early, so nothing is found.
Related Posts:
- Apply jquery script to only woocommerce product pages and categories
- Enqueuing Script in functions.php vs on the page
- jquery won’t load in footer
- Replace menu links with # and add name to its li
- Loading CDN that requires jQuery in WordPress
- Scripts not appending to element in AJAX call – why?
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Run a jquery script on on a certain template page
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to load jQuery in TOP of wp_footer?
- Include Jquery libraries in wordpress theme?
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- Creating multiple category drop down
- How to setup a popup registeration page in wordpress with function.php
- wp_set_object_term via js btn frontend
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Multiple Notifications SetInterval
- Automatic add space if user enters number(any digit)
- Why are some custom javascript files working but some are not
- WordPress Javascript Widget jQuery Dependency Issue
- How do I get my nav menu to show sub pages?
- iOS and ajaxComplete
- Where and how to put inline js in pages
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- How to save Uploaded image in custom option panel?
- How to use WordPress (PHP) functions in AngularJS partials files?
- How to enqueue JavaScript for specific WordPress pages only?
- Display a function using AJAX
- Defer all js except certain ones in functions.php file
- Properly applying nonce to a form using AJAX
- Add external js file to footer with id
- Click loads template via ajax
- Ajaxing function in widget class
- Clean-up script tags
- Search user metadata with checkboxes via ajax (almost working)
- woocommerce target button with class after ajax update
- wp_enqueue JavaScript in child-theme (ReferenceError) using Search & Go
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- How to properly add NPM packages and integrate them in WordPress?
- How to speed up admin-ajax.php in wordpress
- wp_is_mobile dequeue not working
- Why won’t my scripts load?
- wp_register_script(… $in_footer = true) not working
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Wp_query function to search from product_title ‘OR’ product tags name
- Allow Post Author to be 0 on Update
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- How to change the order of Jquery in the footer of my theme?
- Including a specific Javascript Script in a template. Is my code correct?
- Jquery implementation not working on page reload
- Attempt to change jQuery version caused White Screen of Death
- PHP mixed with some JS code to update WordPress theme settings
- Load jquery only for certain pages in the backend
- Add a jQuery Function
- jQuery does not work
- Javascript function not working when placed in Text Block
- I have problems with loading javascripts
- Enqueuing latest version of jQuery into a child theme returns a blank screen
- echo custom fields with AJAX
- Adding javascript to functions.php causes problems with my template
- Dequeue script to prevent javascript event conflict on wordpress child theme
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Loading two different AJAX requests on two different pages
- Enable right click on WordPress site
- Why i can’t get custom fields value or post ID via Ajax?
- The correct way to add a JavaScript in the functions.php [closed]
- Where is this JQuery coming from?
- Javascript not loading after the document ready
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Are innerHTML elements visible to jQuery functions?
- get content from page through AJAX
- Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?
- colorbox not loading in
- Custom attributes to javascript tags
- How to add php within jquery
- wp_enqueue_script() not working
- How to change text color depending on the number value (Using javascript)
- Running javascript without hooking wp_head
- Hide ‘add to cart’ when certain value in dropdown is selected
- Ajax Form Issues using Lightsail (AWS)
- Update $wpdb query with AJAX
- Ajax in plugin fails – but only on one blog – no idea why
- How to add javascript code into Divi child theme?
- How to use `foreach()` in ajax call
- How to call a function from functions.php with ajax?
- Execute jQuery with custom event listener after successfully add an item to the cart
- Find the method which AJAX GET calls
- wordpress ajax is not working for dropdown selection
- WordPress Jquery+scripts enqueue issue
- Moving CDN jQuery to footer does not work?
- Adding a jQuery rotator function
- jQuery HoverIntent is not a function
- Ajax call does not work for this custom code
- Owl Carousel and WordPress Integration Via WP_Enqueue
- Can’t find function which is called in a wordpress theme
- dynamically import array from another js file in WordPress