[resolved] Retrieve Post ID from Body Class with Javascript (3 posts)

  1. lozbo
    Posted 2 years ago #

    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:


    But it's not really what I'm looking for.

  2. Andrew
    Forum moderator
    Posted 2 years ago #

    Look at using jQuery's attribute equals selector function, e.g;

     var class = $('body[class="post-id-47"]');
  3. lozbo
    Posted 2 years ago #

    I'm trying to create a scriptlet, so I think I can't use jquery there.. but thanks a lot for your answer.

Topic Closed

This topic has been closed to new replies.

About this Topic