php - How to get the ids of div looping through foreach in jquery variable -


hello there i'm having trouble in getting id's of div stored in foreach loop. want id 1 one in jquery ids looping in php code.

<script>     $(document).ready(function(){         $(".cat-anchor").click(function(){             var target=('get id of cat-title class here')         });     }); </script> <?php foreach($cat_arr['cat_pro'] $cat_name){ echo "<div class='cat-back'>"; echo "<a href='#".$cat_name[0]."' class='cat-anchor'>".$cat_name[1]."</a> <br>"; echo "</div>"; }      foreach($cat_arr['cat_pro'] $mykey=>$myvalues){         echo '<div name="'.$myvalues[1].'" class="cat-title" id="'.$myvalues[0].'">         <h2>'.$myvalues[1].'</h2></div>'; ?> 

<script>     $(document).ready(function(){         $(".cat-anchor").click(function(){             $(".cat-title").each(function(index, element) {                 var target=$(this).attr("id");             });         });     }); </script> 

trying this, you'll object each div , use them as wish.


Comments