badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Reply To: The JavaScript for Accordion does not work

#44622
ilayxz
Participant

Thank you very much for your recommendation! It has very helped! 🙂

First I did my script code at interface-child/header.php inserted. So It works marvellous!

But than I was going to enqueue it from functions.php to head section.

Thereto I made the following steps:

  1. In interface-child/header.php in <head>-area the following code inserted:
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
  2. A new javaScript created: accordion.js in file interface-child/js:
    $(document).ready(function(){
                    $("dt").click(function(){
                        $('dd').slideUp("fast");
                        $('dt > a').removeClass('open').addClass("closed");
                        $(this).next("dd").slideDown("fast");
                        $(this).children("a").removeClass('closed').addClass("open");
                    });
                });
  3. To Loading the scripts properly in WordPress, I did pasted the following code in my child-theme’s functions.php file:
    function wp_interface_scripts() {
                    wp_register_script('my_accordion_script', plugins_url('accordion.js', get_stylesheet_directory() . 'js/accordion.js'), array('jquery'),'1.0.0', false);
                    wp_enqueue_script('my_accordion_script');
                }
                add_action( 'wp_enqueue_scripts', 'wp_interface_scripts' );

Unfortunately it doesn’t work. Where do I make mistake?

Thank you very much again!