jQuery, obtained variable from HTML class in WordPress loop, how to edit that variable?

I’m working on a WordPress theme, and during the loop, it puts the_ID on each class. So, I have like a couple posts with the class “teamPost-138”, “teamPost-222”, etc…

I have stored that “teamPost-###” in a jQuery variable, and now I need to take off the “teamPost-” part. Is there a way I can cut that in the variable, or can I just select the number part from the class in the HTML?

Related posts

Leave a Reply

2 comments

  1. I’m not entirely clear on what your doing, is it just to assign the number to the variable instead of the teamPost-###?

    Below is some code that you may be able to repurpose. For every element that has a class starting with ‘teamPost-‘ it logs (to the firebug console) the number from their class. The index of isused to negate issues of the item having multiple classes.

    e.g.

    $('[class^=teamPost-]').each(function () {
        var class = $(this).attr('class');
        var numStart = class.indexOf('teamPost-')+9;
        console.log(class.substring(numStart,numStart+3));
    });
    

    If its simply stripping the start of the variable then you just need the strubgstring part:

    'teamPost-123'.substring(9); // equals '123'