Search code examples
phpjquerydynamic-data

Can I change items in jquery dynamically?


I have the following jquery.

$(function() {
$('div#slideshow').append('<img src="images/forsiden/grans_julebrus.jpg" /><img src="images/forsiden/cappelen_hippo.jpg" /><img src="images/forsiden/capplen_grandmarap.jpg" /><img src="images/forsiden/agm_peace.jpg" /><img src="images/forsiden/cappelein_aboriginee.jpg" />');
...
...

I want to add all the image dynamically with php.

<?php echo $images; ?>

Is there any way I can do it?


Solution

  • If the JS function is in it's own .js file, then by default you cannot inject PHP code inside.

    One way to do it is to hide the filenames in the document using hidden input fields (or hidden divs etc) and use jQuery to get them, or you can use jQuery's AJAX functions to request filenames from a PHP handler.