wordpress - get link attribute id using jquery -
i working in wordpress.i want data-id value when click on link.
my code this:
<?php $query3 = "select t.* wp_terms t join wp_term_taxonomy tt on tt.term_id = t.term_id tt.parent = ".$res2->term_id; $result3 = $wpdb->get_results($query3); foreach($result3 $res3) { ?> <li> <a href="##" class="sub_cat_name" data-id= "<?php echo $res3->term_id; ?>"><strong><?php echo $res3->name; ?></strong></a> </li> <?php } ?>
and jquery code is:
<script> $(document).ready(function(){ $(".sub_cat_name").click(function(){ var cat_id = $(".sub_cat_name").attr("data-id"); alert(cat_id); }); }); </script>
when click on different link alert fist term_id.so code should have write different id while click on different link.
you can data-id value using 'data' like.
$(".sub_cat_name").click(function(){ var cat_id = $(this).data("id"); alert(cat_id); });
Comments
Post a Comment