• 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)
  • Thread Starter hi7tek

    (@hi7tek)

    sorry, the output is:

    test12
    test12
    test12
    test12

    after every post (that’s where the jquery display div is)

    I need the output to be unique every time

    I know I can do it easily with php. The problem is that it is very important that I can do the same in jQuery as this is crucial for my project

Viewing 1 replies (of 1 total)
  • The topic ‘Post id to jQuery on archive page’ is closed to new replies.