Title: Javascript Converting &lt; to HTML Code
Last modified: September 26, 2016

---

# Javascript Converting < to HTML Code

 *  [randy394](https://wordpress.org/support/users/randy394/)
 * (@randy394)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/javascript-converting-to/)
 * 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 9 years, 8 months ago by [randy394](https://wordpress.org/support/users/randy394/).
    -  This topic was modified 9 years, 8 months ago by [randy394](https://wordpress.org/support/users/randy394/).
    -  This topic was modified 9 years, 8 months ago by [randy394](https://wordpress.org/support/users/randy394/).

Viewing 1 replies (of 1 total)

 *  [SJW](https://wordpress.org/support/users/whitsey/)
 * (@whitsey)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/javascript-converting-to/#post-8224505)
 * 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.

## Tags

 * [converting](https://wordpress.org/support/topic-tag/converting/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [SJW](https://wordpress.org/support/users/whitsey/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/javascript-converting-to/#post-8224505)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
