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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:46:00+00:00 2026-06-01T06:46:00+00:00

Say I have the following element: <p id=thingy>Here is some <em>emphasized</em> text!</p> In a

  • 0

Say I have the following element:

<p id="thingy">Here is some <em>emphasized</em> text!</p>

In a Javascript console, I’ll get its contents with jQuery:

> var theContents = $('<p id="thingy">Here is some <em>emphasized</em> text!</p>').contents();

theContents is now an array that looks like this:

> theContents
["Here is some ", <em>​emphasized​</em>​, " text!"]

So far so good; it seems to be an array, where elements 0 and 2 are strings, and element 1 is a jQuery object. If I output just the first element, it seems to confirm my guess:

> theContents[0]
"Here is some "

However, if I try to concatenate it with another string, I see that I am lacking some understanding:

> 'Hello! ' + contents[0];
"Hello! [object Text]"

So that variable looks like a string, but it is in fact some kind of object. For that matter, the jQuery object in the middle doesn’t show up as a regular object, either; it shows up as the raw markup.

Another question references the same problem, but doesn’t actually explain it. I’ve found that I can use contents[0].textContent to solve my real problem, but that still doesn’t help me understand exactly what is going on here. Can someone explain to me in detail why all this is behaving the way it is?

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

    Most jQuery functions return a jQuery object, which for convenience looks and works like an array for most purposes. To quote the documentation, “A jQuery object contains a collection of Document Object Model (DOM) elements” (or “nodes”). So you can assume that each member of the collection is a DOM node, not a string, and accordingly the object you’re looking at is a Text node.

    In JavaScript when you do string concatenation each operand that isn’t a string is automatically converted to one by calling its toString() method. So, just as “1,2,3” is the string representation of the array [1, 2, 3] and “[object HTMLDivElement]” represents a node created with the HTML “<div>“, “[object Text]” represents a Text node.

    You can read the specification here. Since interface Text inherits from CharacterData it has a data property that contains the string itself. And so:

    var theContents = $( '<p id="thingy">Here is some <em>emphasized</em> text!</p>' )
                        .contents();
    
    console.log( theContents[0].data );
    // => "Here is some "
    
    console.log( "Hello! " + theContents[0].data );
    // => "Hello! Here is some "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following HTML: <div> <span>span text</span> div text <span>some more text</span>
Say I have the following DOM element in my piece of code: <div id=test>
Lets say I have the following situation (some rough pseudocode): struct { int i;
Let's say I have following jQuery line where I am trying to change the
Let's say I have the following scenario: <form action=/something.php method=GET>Click me</div> <script type=text/javascript><!-- $('form').submit(function(e)
Let say I have the following DOM element on my page: <div id=name>Sharon</div> Q1:
Lets say I have the following jQuery plugin (this is just an example to
Say I have the following markup <div><p></p><blockquote></blockquote><ul>...</ul></div> <div><p></p><blockquote></blockquote><ul>...</ul></div> ... <div><p></p><blockquote></blockquote><ul>...</ul><ul></ul></div> Is there a jQuery
Consider the following : I have several arrays (let's say 2), that I get
Lets say we have following models. class User(db.Model): username=db.StringProperty() avatar=db.ReferenceProperty() class User(db.Model): username=db.StringProperty() avatar=db.StringProperty()

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.