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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:15:10+00:00 2026-05-27T21:15:10+00:00

<div id=myDiv class= blueberry mango ></div> If we use the .addClass() $(#myDiv).addClass(carrot); The class

  • 0
<div id="myDiv" class=" blueberry mango "></div>

If we use the .addClass()

$("#myDiv").addClass("carrot");

The class for myDiv is now "(no-space)blueberry mango(double-space)carrot"

There is a left-trim, but there are double spaces between mango and carrot because there were no right-trim

  • Is there a particular reason why jQuery’s addClass() is not
    right-trimming?
  • Or the left-trim was not even intended?
  • 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-27T21:15:11+00:00Added an answer on May 27, 2026 at 9:15 pm

    Seems like jQuery is doing the trim after adding the class. See jquery addclass code below,

    addClass: function( value ) {
        var classNames, i, l, elem,
            setClass, c, cl;
    
        if ( jQuery.isFunction( value ) ) {
            return this.each(function( j ) {
                jQuery( this ).addClass( value.call(this, j, this.className) );
            });
        }
    
        if ( value && typeof value === "string" ) {
            classNames = value.split( rspace );
    
            for ( i = 0, l = this.length; i < l; i++ ) {
                elem = this[ i ];
    
                if ( elem.nodeType === 1 ) {
                    if ( !elem.className && classNames.length === 1 ) {
                        elem.className = value;
    
                    } else {
                   //HERE IS APPENDS ALL CLASS IT NEEDS TO ADD
                        setClass = " " + elem.className + " ";
    
                        for ( c = 0, cl = classNames.length; c < cl; c++ ) {
                            if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
                                setClass += classNames[ c ] + " ";
                            }
                        }
                        elem.className = jQuery.trim( setClass );
                    }
                }
            }
        }
    
        return this;
    }
    

    So it’s like below,

    jQuery.trim(" blueberry mango " + " " + "carrot")

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

Sidebar

Related Questions

Let's say I have <div class=myDiv>Hi there</div> I want to put a background-image and
My div with class name 'header-body-right' doesn't seem to be floating to the left
I have <span> inside a <div> , like so: <div id=#mydiv> <a href=#>Hello</a><span class=myImageArea></span>
#mydiv { position:absolute; left:0px; top:0px; width:83px; height:83px; } <div id=mydiv></div> That's my style for
My HTML is something like this <div id=mydiv class=common> <input type=text id=text1 value= />
.myDiv { background: url(/images/myimage.jpg); margin: 0 auto; } <div class=myDiv> Click Me! </div> I
I have a page containing the following div element: <div id=myDiv class=myDivClass style=>Some Value</div>
With regard to the following markup: <div class=mydiv> <a href=index.php><img src=myimage.gif /></a> </div> The
Say i have this: <div class='myDiv'> <p>hello</p> hello <p>Hello</p> </div> How does one grab
Using the following code: <a href=/someurl> <div class='mydiv' onMouseOver=document.getElementById('myid').sendEvent('play'); onMouseOut=document.getElementById('myid').sendEvent('stop');> <div id='myid'></div> <script type=text/javascript>

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.