WordPress.org

Ready to get started?Download WordPress

Forums

Get Page or Post ID from JavaScript (2 posts)

  1. eloyrubio
    Member
    Posted 2 years ago #

    I want to get a Post id from a javascript function in the post editor. I tried this code, but does not work for me:

    <script>
    function get_post_content(){
       return document.getElementById("post-"+id).innerHTML;
    }
    </script>
    
    <a href="#" onclick="get_post_content(<?php the_ID(); ?>);">Next</a>

    Thank you in advance.

  2. KajMagnus
    Member
    Posted 2 years ago #

    You haven't included any parameter in get_post_content(){ ...;
    this should work better: get_post_content(id){ ...

Topic Closed

This topic has been closed to new replies.

About this Topic