javascript - repeat functions in jquery based on variable in php -


i have group of images in webpage each 1 has it's own id, of id's saved in php array. want write script take id php array , pass client side , repeat jquery function each image. here did:

<script>     <? php ($i = 0; $i < $counterpostid; $i++) {         $str = "#post".$arrid[$i]; ?>         var myvar = <? php echo json_encode($str); ?> ;         var myvar2 = myvar + " " + "#textcaption";          //functions repeated each image         jquery(myvar).mouseover(function() {             jquery(myvar2).slidedown("slow");         }).mouseout(function() {             jquery(myvar2).slideup("slow");         });      <? php } ?> </script> 

the code work fine last occurrence in loop, want jquery code repeated images. how can that?

assuming $counterpostid array id's, can implode selector

var selector = '<?php echo "#post" . implode(", #post", $counterpostid); ?>'; // should output -> '#postid1, #postid2, #postid3' ... etc  $(selector).on('mouseenter mouseleave', function() {     $('.textcaption', this).slidetoggle('slow'); // use class, not same id }); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -