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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:05:26+00:00 2026-05-27T18:05:26+00:00

I have the following statement in document.ready function: if($(sidebar ).html().trim().length == 0) { $(sidebar).append(<p>&nbsp;&nbsp;&nbsp;The

  • 0

I have the following statement in document.ready function:

  if($("sidebar ").html().trim().length == 0)
  {
    $("sidebar").append("<p>&nbsp;&nbsp;&nbsp;The sides..</p>"); 
  };

It works fine in IE 9 but as soon as I select IE 8 (browser and document standard), the script stops working and gives the following error:

SCRIPT5007: Unable to get value of the property 'trim': object is null or undefined 
application-e51c9eee7d22e9644481115dc1fedd5f.js, line 7 character 17578

I looked at the .js in debug mode and see that my statement above is transformed to:

$("sidebar ").html().trim().length==0&&$("sidebar").append("<p>&nbsp;&nbsp;&nbsp;The sides..</p>")

How do I prevent this error? Please note that I do see that the node is present in the rendered page.

I thought that maybe just having reference to shiv5.html may not be sufficient to take care of the IE idiosyncrasies. So, I have added modernizr.js via sprockets and I have added class=”no-js” in my layout. Still no luck in IE <9.

What am I missing? What else can I do to get the favor of Microsoft overlords?

  • 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-27T18:05:27+00:00Added an answer on May 27, 2026 at 6:05 pm

    According to MDN, trim isn’t available in IE < 9.

    You could use $.trim instead:

    if($.trim($("sidebar ").html()).length == 0)
    {
      $("sidebar").append("<p>&nbsp;&nbsp;&nbsp;The sides..</p>"); 
    } // <-- Don't want a semicolon here.
    

    The MDN article lists an alternative if you don’t want to find all the instances of trim and correct them. You could use the following to create .trim if it’s not natively available:

    if(!String.prototype.trim) {
      String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/g,'');
      };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 checkboxes with the following jQuery and it works great. $(document).ready(function() {
I have the following function. Everything works, except for the 'if' statement as noted
I have the following function in JavaScript every part of the if statement executes
I have the following code which works perfectly but I need an onblur statement
I have the following jQuery statement which works fine but I was wondering if
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
I have following LINQ statement and I want to rewrite it using extension methods.
I have the following statement SELECT id, descr from mytable which returns 1, 'Test1'
I have an ASP MVC view where have the following statement #if DEBUG //section
I've modified my .htaccess file to have the following statement RewriteCond $1 !^index.php$ RewriteRule

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.