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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -