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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:03:54+00:00 2026-05-28T15:03:54+00:00

The code below throws an exception in firefox: $(function(){ $([one,two,three]).each(function(){ if(this == one) $(div#msg).html(this);

  • 0

The code below throws an exception in firefox:

 $(function(){
        $(["one","two","three"]).each(function(){
            if(this == "one")
                $("div#msg").html(this);
        });
    });

the exception is this:

Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]

Yet if I change code and use this.toString() as follows, it works:

$(function(){
    $(["one","two","three"]).each(function(){
        if(this == "one")
            $("div#msg").html(this.toString());
    });
});

If “this” is a string, why do I need to do toString()? Is there a nuance of javaScript which I am missing or am I just being a moron? Please tell me it’s a nuance.

  • 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-28T15:03:56+00:00Added an answer on May 28, 2026 at 3:03 pm

    Distinction between string primitives and String objects JavaScript automatically converts primitives and String objects, so that it’s possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.

    ~From MDN Read More

    $("div#msg").html("one"); //works
    
    $("div#msg").html(new String("one")); // doesnt work
    

    For ex:

    try {         
        $("div#msg").html(new String("one"));
    } catch (e) {
        $("div#msg").html("Can't use String object");
    }
    

    And the output of the div is Can't use String object. Demo here

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

Sidebar

Related Questions

Hi I have below pseudo code with throws an exception like this throw new
The below code in Java throws Null pointer exception. public class New{ int i;
EDIT: The code below throws no exception but has no output and hangs. It
The Grails code below throws the following exception when trying to .save() the Foo
I have 2 issues with the code below: push(o) throws an exception TypeError: can
I have written code below.but it will print this exception and i really don't
Why is an exception being thrown in the f++ part of the code below
e.g. The code below throws a ClassCastException when the second Object is added to
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Look please below this codes throw me : FormatException was unhandled by user code

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.