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 8487089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:08:06+00:00 2026-06-10T21:08:06+00:00

I am importing via RSS various news articles from various sources (all beyond my

  • 0

I am importing via RSS various news articles from various sources (all beyond my coding/formatting control) into my client’s database (all legal!) and I am attempting to standardize some of their styling for presentation on client’s site via jQuery. For example…

Many many sites use various header tags seemingly for formatting only. When these are pulled into client’s presentation they look like crap, so I have working code to find and replace these code blocks with a styled paragraph (the semantics of this code are not important, we mainly link back to original source), and it works fine. Code:

$(document).ready(function() {
    $('#selector h1, #selector h2:not(.article_name), #selector h3, #selector h4, #selector h5').replaceWith(function() {
        return '<p class="h_replace">' + $(this).text() + '</p>';
    });
});

The .h_replace CSS simply enlarges the <p> and adds some other attributes to make it more heading-like. So far, so good.

But here’s where I’m hitting a wall: same sites also often use a <p> immediately followed with a child <b> as the only content to substitute/act as a heading.

I want to find and replace these code blocks with a styled paragraph (as above), but I am unsuccessful selecting any <p> that contains ONLY a <b> element. That is to say I want to select this:

<p><b>Some content here.</b></p>

and not this:

<p><b>Some Bold Text:</b> and some NOT bold text.</p>

In the first example, the <p> contains ONLY a child <b> element. In the second example the <p> contains a child <b> element as well as paragraph text not enclosed in the child <b>.

I am looking to programmatically select only the first type of <p>, and not the second.

Any ideas?

Here’s what I’ve got so far, but it selects both instances:

$(document).ready(function() {
    $('#selector p b:only-child').parent('p').replaceWith(function() {
        return '<p class="h_replace">' + $(this).text() + '</p>';
    });
});

The :only-child selector I thought would be a magic bullet, but then, of course, the <b> IS the only child of the <p> in both cases.

I need to select paragraphs that contain only and nothing but <b> content.

I hope that’s clear.
As always, any help is always greatly appreciated.

  • 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-06-10T21:08:08+00:00Added an answer on June 10, 2026 at 9:08 pm

    Try this:

    var els = $('p').filter(function() {
        return /^<(b)>.+<\/\1>$/.test($.trim($(this).html()));
    });
    

    It will get you all p that have an only children b without any text nodes. You can change (b) with whatever tag in the code above.

    Edit: Don’t know why the downvote but this works just fine:

    • <p><b>Something</b></p> // true
    • <p> <b>Something</b> </p> // true
    • <p><b>Something</b> lorem</p> // false
    • <p>lorem <b>Something</b></p> // false
    • <p><span><b>Something</b></span></p> // false

    Demo: http://jsfiddle.net/elclanrs/LFt8x/

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

Sidebar

Related Questions

I'm importing a function from an unmanaged DLL into C#. The C++ function signature
I am importing data from MySQL to PowerPivot. I have all of the relevant
I have a question regarding importing( Via the import/export wizard) an excel spreadsheet into
Our client needs to import Contact information from a partner org via Salesforce to
Context We're adding group membership filtering when importing members from an LDAP server into
Im importing HTML into my page via an XML feed. If the content has
I want to write an import function for importing data from a website into
Importing a Maven project into Eclipse has brought up the error: Plugin execution not
After importing content from a legacy website using the Feeds module, I'm left with
Upon importing the JSONKit.h and JSONKit.m files into my project , i get the

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.