Title: WP PHP   Javascript Timing Help Needed!
Last modified: August 18, 2016

---

# WP PHP Javascript Timing Help Needed!

 *  Resolved [CMoseley](https://wordpress.org/support/users/cmoseley/)
 * (@cmoseley)
 * [19 years, 2 months ago](https://wordpress.org/support/topic/wp-php-javascript-timing-help-needed/)
 * Okay, so my problem is this. I’m using a javascript code to hide information 
   in my posts and when a user clicks on a button, that information displays. But
   when I run the page, I get an error, “switchcontent” is not defined. It should
   be getting its definiation from a tag that has an id of “meta<?php the_ID(); ?
   >-title” which will allow the javascript to associate that button with the div
   that has the id “meta<?php the_ID(); ?>”.
 * So my guess is that the “timing” is off. If my rudimentary understanding of WordPress
   is correct, after a call to index.php, the php goes and “builds” wordpress, which
   then goes and runs the template file. The template file first executes all the
   normal code in it (and thus the javascript runs), then it executes all wordpress
   specific PHP tags (which would by why the javascript fails, since the its relying
   on the wordpress specific tags to generate needed information).
 * My theory is further reinforced by the fact that if I copy my code that failed
   from wordpress, and paste it into a static html file, the page works flawless
   as intended.
 * So is there any way I can get the javascript to run after the template file populates
   all its information from wordpress specific php tags?
 * I tried enclosing the javascript into WP conditional tags that would echo the
   code, but that didnt work either.
 * For referance, the JS code i’m trying to implement is this one:
    [http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm](http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm)
 * Thanks in advanced for any help!

The topic ‘WP PHP Javascript Timing Help Needed!’ is closed to new replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [js](https://wordpress.org/support/topic-tag/js/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [template_tags](https://wordpress.org/support/topic-tag/template_tags/)
 * [timing](https://wordpress.org/support/topic-tag/timing/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [CMoseley](https://wordpress.org/support/users/cmoseley/)
 * Last activity: [19 years, 2 months ago](https://wordpress.org/support/topic/wp-php-javascript-timing-help-needed/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
