jQuery running before PHP has finished

thiagoql

New Member
I have a \[code\]for\[/code\] loop in PHP that creates four \[code\]div\[/code\], each containing a \[code\]img\[/code\] and \[code\]p\[/code\] string, as below:\[code\]<div class="guest-tile-holder"> <img class="guest-tile" src="http://stackoverflow.com/questions/14549670/<?php echo($tile); ?>"> <p><span><?php echo($fn.' '.$ln); ?></span></p></div>\[/code\]In jQuery, I want to colour every fourth \[code\]p\[/code\] black, i.e. only the \[code\]p\[/code\] string the fourth box created, as below:\[code\]$(document).ready(function() { $('p:nth-child(4)').css('color', 'black');});\[/code\]What I would expect is that the PHP would pre-process, creating four \[code\]div\[/code\] as above and then jQuery would colour black the \[code\]p\[/code\] string in the fourth \[code\]div\[/code\]. What is actually happening however is jQuery appears to be ignoring the PHP and colouring a \[code\]p\[/code\] string that is another three \[code\]p\[/code\] strings away in my HTML.I was always led to believe that PHP would pre-process, therefore I don't understand why jQuery appears to be running before the PHP has completed.Can anybody tell me how I would get the jQuery to run after PHP has finished?
 
Back
Top