Post id to jQuery on archive page
-
Hi, I’m trying to get $post->ID value to jquery so that I will get dynamic value.
to achieve this I’ve got the following code:
<input class="post_id_input" type="hidden" value="<?php echo $post->id;?>" /> <div class="jquery_display"></div> <!-- jquery data placeholder -->
and then here is my jquery:
<script type="text/javascript"> var id = $( '.post_id_input' ).val(); $ ( '.jquery_display' ).text('test' + id); </script>
However the effect is that only the id of the first post is being displayed even though the id in hidden field changes ok
the output is:
test + 12
test + 12
…Why is it behaving like this?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Post id to jQuery on archive page’ is closed to new replies.