Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need help activating Javascript file in my wordpress child theme?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #159031
    iizag
    Participant

    Hi I am new here to JavaScript, and I just started learning I use WordPress to create my websites. I created a javascript file called my script, then Put that script tag into my index.php of parent theme then added javascript file to wordpress child theme but that Javascipt file is not working ? I tested it by trying to change the color of a new div I added by using the document.getElementById("Myscript").style.backgroundColor = "#f0a" —- But nothing is showing so I assume the index.php file script was not activated correctly ?

    Any help would be great , thank you

    Ok so inside my parent themes index.php file (ill paste the last couple of lines) at the very end there is :

    </div> <!-- #main -->
            </div> <!-- #main-container -->
    
    
    
    
    <?php get_footer(); ?>
    <script src="myscript.js"></script>
    

    Inside one of my pages to test if the javascript file I added was working, I put:

    <div id="myDiv">
    words sdfdsf dfs fdsf fds
    </div>
    

    My java script file thats in my child theme ( named myscript.js) I put :

    document.getElementById('myDiv').style.background = "black";
    
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.