• I am having difficulty with the below Javascript, where < is getting converted to HTML code when loading in the browser.

    I’ve tried putting the code into a separate .js file, but it still isn’t working, I’m guessing because it’s outside the loop.

    <script>
    var acc = document.getElementsByClassName("accordion");
    var i;
    
    for (i = 0; i < acc.length; i++) {
        acc[i].onclick = function(){
            this.classList.toggle("active");
            this.nextElementSibling.classList.toggle("show");
      }
    }
    </script>
    • This topic was modified 8 years, 2 months ago by randy394.
    • This topic was modified 8 years, 2 months ago by randy394.
    • This topic was modified 8 years, 2 months ago by randy394.
Viewing 1 replies (of 1 total)
  • If you put this into a separate js file then you don’t need the <script> tag

    You just load that file using a script tag in itself:

    <script src="myscripts.js"></script>

    Load it via functions.php:

    function wpb_adding_scripts() {
    wp_register_script('my-scripts', get_template_directory_uri() . '/js/myscripts.js','','1.1', true);
    wp_enqueue_script('my-scripts');
    }
    add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' ); 
Viewing 1 replies (of 1 total)
  • The topic ‘Javascript Converting < to HTML Code’ is closed to new replies.