WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. lozbo
    Member
    Posted 1 year 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:

    http://wordpress.org/support/topic/post-id-in-javascript?replies=7

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

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

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

    jQuery(document).ready(function($){
     var class = $('body[class="post-id-47"]');
    });
  3. lozbo
    Member
    Posted 1 year 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