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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:16:58+00:00 2026-06-13T06:16:58+00:00

What I need to do is grab the first <p> tag within an element,

  • 0

What I need to do is grab the first <p> tag within an element, loop through all of the words, and wrap them in <span> tags. I wrote a script for this, which I thought worked, but it appears to break when some characters are in the <p> tag. I don’t know which character(s) that causes it to break though.

Here is my current code:

$(document).ready(function(){
// Transform is set on html tag by modernizr
// Apply this on all .quote boxes, even if there are multiple (most likely aren't)
$('.csstransforms .quote').each(function() {
    // Get data
    var elem = $(this).find('p:first'),
        html = elem.text(),
        words = html.split(" "),
        charCount = html.length

    $(this).append('<p class="fixed"></p>');

    // Add new words
    var tmpWord = '';
    for(i=0; i< words.length ; i++) {
        tmpWord = $.trim(words[i]);

        if(tmpWord && tmpWord != "") {
            // Maybe replace with $(elem).next('.fixed') or something?
            $('.csstransforms .quote .fixed').append('<span>'+ tmpWord +' </span>');   
        }
    }

    // Check word count, make size smaller if needed
    if(charCount > 150) {
        // Add class to .quote box
        $(this).addClass('smaller');
    }

    // Hide original <p>
    $(elem).hide();
});
});

The error i’m getting is as follows, and what you see in the text is the actual quote:

Uncaught Error: Syntax error, unrecognized expression: "In the decade or so, science has discovered a tremendous amount about the role emotions play in our lives. Researchers have found that even more than IQ, your emotional awareness and abilities to handle feelings, will determine your success and happiness in all  walks of life, including family relationships". – John Gottman, Ph. D. 

Any ideas as to what is causing this, and how to fix it? Been chewing on it on a while without success.

Update: Jsfiddle showing same error: http://jsfiddle.net/Uugbc/

  • 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-13T06:17:00+00:00Added an answer on June 13, 2026 at 6:17 am

    Just for clarification. Your fiddle has
    charCount = $(html).text().length;
    but your variable html is not a jQuery object.

    This will work better

        var elem = $(this).find('p:first'),
            html = elem.text(),
            words = html.split(" "),
            charCount = html.length; // here you had $(html).text().length;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to grab for the name for a input field. All of them
I need to loop through an entire list of users, but need to grab
I need to grab all categories that don't have subcategories 1 ^--1.1 ^--1.2 ^--1.2.3
I need to grab inline script tags inside html pages. The regex will eventually
I need to grab all the FIELD and VALUES from a POST. I have
I need to grab the words out of this string and replace with AND
I need to grab first word in string and I need to convert it
Alright, first you'll need to grab a barf bag. I've been tasked with optimizing
I need to grab certain parts from many tables, save them and finally generate
I have an array result that contains multiple arrays. I need to grab all

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.