Title: Get Page or Post ID from JavaScript
Last modified: August 20, 2016

---

# Get Page or Post ID from JavaScript

 *  [eloyrubio](https://wordpress.org/support/users/eloyrubio/)
 * (@eloyrubio)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/get-page-or-post-id-from-javascript/)
 * 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.

Viewing 1 replies (of 1 total)

 *  [KajMagnus](https://wordpress.org/support/users/kajmagnus/)
 * (@kajmagnus)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/get-page-or-post-id-from-javascript/#post-2488528)
 * You haven’t included any parameter in `get_post_content(){ ...`;
    this should
   work better: `get_post_content(id){ ...`

Viewing 1 replies (of 1 total)

The topic ‘Get Page or Post ID from JavaScript’ is closed to new replies.

## Tags

 * [$post->id](https://wordpress.org/support/topic-tag/post-id/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [Page ID](https://wordpress.org/support/topic-tag/page-id/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [KajMagnus](https://wordpress.org/support/users/kajmagnus/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/get-page-or-post-id-from-javascript/#post-2488528)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
