Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:03:11+00:00 2026-05-25T17:03:11+00:00

I have a situation where I am sorting through a list of blog posts

  • 0

I have a situation where I am sorting through a list of blog posts in a custom CMS. Each blog post is wrapped in a <li> and there are multiple posts on the page. I have code that puts in a sharethis button set on each blog post. Unfortunately all the class names for a blog post start with “post”. For example;

<div class="blogList">
     <ul>
          <li class="post1">
               <h2 class="postTitle">A Sample Title</h2>
               <div class="postDescription">Some sample content</div>
          </li>

          <li class="post2">
               <h2 class="postTitle">A Sample Title</h2>
               <div class="postDescription">Some sample content</div>
          </li>
     </ul>
</div>

I was sorting through this with an “.each” on the li but that ended up adding it to the lists that are included in any post content itself. So I want to only add this once onto the actual parent li of each individual blog post.

What I’m trying to do is add it only to the <li> with a class of “post” and then a number. I can’t just look for post since it also will add it onto any other item with the class of “post” as it’s starting name.

How can I select only the elements with only the class of “post” and a number? So I would want to find only elements in the above example of li.post1, li.post2 . All other elements would be skipped.

I’m doing this in jquery and I feel like I’m close but just can’t seem to get over this hump.

Below is the code example I’m using in it’s entirety.

<script type="text/javascript">
    $(document).ready(function(){

        //Run through the page and find each individual blog post
        $('.blogList li [class^="post"]').each(function () {

            //Grab post title & encode any quotes so they don't mess up generated HTML
            var postTitle = $.trim($(this).children(".postTitle").text().replace('"g, "'));

            //Grab URL from the anchor element inside the h2 element (will not grab correct link in admin mode)
            var postLink =  location.protocol + '//' + location.host + $(this).children("h2").find("a[href]").attr('href');

            //Add "share this" HTML elements to the bottom of the post
            $(this).append(
                 '<div class="st">' + 
                    '<span  class="st_twitter" displayText="Tweet" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                    '<span  class="st_facebook" displayText="Facebook" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                    '<span  class="st_linkedin" displayText="LinkedIn" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                    '<span  class="st_email" displayText="Email" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                    '<span  class="st_blogger" displayText="Blogger" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                    '<span  class="st_sharethis" displayText="ShareThis" st_url="' + postLink + '" st_title="' + postTitle + '"></span>' +
                '</div>'
            );  
        });
    }); 
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:03:11+00:00Added an answer on May 25, 2026 at 5:03 pm

    You just need to use a more specific class selector. This rule should get what you need:

    $('div.blogList>ul>li[class^="post"]')
    

    That will get you only direct child li’s with a class of post* that are direct children of a UL that is a direct child of a div with a class of blogList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation where there are multiple test cases which uses a common method.
Say, we have some items, and each defines some partial sorting rules, like this:
I have situation where I need to authenticate a client across multiple web services.
I have got a weird situation. There is an array that has got numbers
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation, where running a query that filters by an indexed column in
I have situation in which I read a record from a database. And if
I have situation where I need to change the order of the columns/adding new
I have situation where a user can manipulate a large set of data (presented
I have situation like this: user submits form with action='/pay' in '/pay' I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.