Title: Retrieve Post ID from Body Class with Javascript
Last modified: August 20, 2016

---

# Retrieve Post ID from Body Class with Javascript

 *  Resolved [lozbo](https://wordpress.org/support/users/lozbo/)
 * (@lozbo)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/retrieve-post-id-from-body-class-with-javascript/)
 * I have this html outcome:
 * `<body class="single single-post postid-1489 single-format-standard inner-page"
   >`
 * And I want to get the post ID number (only the number, without “postid-“) with
   JavaScript.
 * This is as close as I’ve gotten:
 * `document.body.(class*=' postid-').value`
 * But I’m afraid its not getting the job done.
 * I found this thread:
 * [http://wordpress.org/support/topic/post-id-in-javascript?replies=7](http://wordpress.org/support/topic/post-id-in-javascript?replies=7)
 * But it’s not really what I’m looking for.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 5 months ago](https://wordpress.org/support/topic/retrieve-post-id-from-body-class-with-javascript/#post-3354200)
 * Look at using jQuery’s [attribute equals selector](http://api.jquery.com/attribute-equals-selector/)
   function, e.g;
 *     ```
       jQuery(document).ready(function($){
        var class = $('body[class="post-id-47"]');
       });
       ```
   
 *  Thread Starter [lozbo](https://wordpress.org/support/users/lozbo/)
 * (@lozbo)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/retrieve-post-id-from-body-class-with-javascript/#post-3354222)
 * I’m trying to create a scriptlet, so I think I can’t use jquery there.. but thanks
   a lot for your answer.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Retrieve Post ID from Body Class with Javascript’ is closed to new replies.

## Tags

 * [id](https://wordpress.org/support/topic-tag/id/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [postid](https://wordpress.org/support/topic-tag/postid/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [lozbo](https://wordpress.org/support/users/lozbo/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/retrieve-post-id-from-body-class-with-javascript/#post-3354222)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
