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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:40:23+00:00 2026-05-23T02:40:23+00:00

Using .text object property in JavaScript can produce unexpected results in IE8 (blank string

  • 0

Using .text object property in JavaScript can produce unexpected results in IE8 (blank string or undefined even when it contains a value).

You can use .innerHTML object property as a workaround. IE8 seems to like this.

Or, for reliable cross-browser compatability you can use jquery instead to access an object’s text property and I could have do so with: $(this).text() See the answer for a good jQuery solution.

Original Question: Is, ‘text’ a reserved javascript word in IE8? I am curious because I could not find any resource that states this.

*JavaScript (optionObj.innerHTML) Solution: *

// Look for a match in the section dropdown and select it.
$.each($('#' + mySelect + ' option'), function(key, optionObj) {

    // Switched 'optionObj.text' to 'optionObj.innerHTML' for cross-browser compatibility
    if (optionObj.innerHTML == strTextToMatch) {
        // Found a match
        $('#' + mySelect).val(optionObj.text);
        $('#' + mySelect).trigger('change');
    }
});

In IE8, optionObj.text would sometimes return a blank string, even when I could see in my debugger that it contained a value (I could see by expanding the optionObj object)! What was strange is that 10% of the time, optionObj.text would return the actual value other than a blank string. That being said, optionObj.innerHTML seems to work reliably.

  • 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-23T02:40:24+00:00Added an answer on May 23, 2026 at 2:40 am

    No, text is neither a reserved word, nor a future reserved word, in JScript.

    http://msdn.microsoft.com/en-us/library/0779sbks(v=vs.85).aspx


    Edit OH, I see it now.

    You’re using the wrong each function — $.each() instead of .each().
    You’re also using .text instead of .text(). Fixes:

    var $mySelect = $('#' + mySelect);
    $mySelect.find('option').each(function()
    {
        var $option = $(this),
            text = $option.text();
        if (text == strTextToMatch) {
            // Found a match
            $mySelect.val(text);
            $mySelect.trigger('change');
        }
    });
    

    but guess what: that’s is totally unnecessary. This will suffice:

    var $mySelect = $('#' + mySelect),
        newVal = $mySelect.find('option:contains(' + strTextToMatch + ')').val();
    $mySelect.val(newVal).change();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm binding a domain objects property to the Text property of a System.Windows.Forms.Label using
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I'm using java.text.SimpleDateFormat to parse string representations of date/time values inside an XML document.
How can I output colored text using printf on both Mac OS X and
I'm using the After Effects CS3 Javascript API to dynamically create and change text
I have the following JavaScript (I'm using jQuery): function language(language) { var text =
Using knockout.js, is it possible to bind to a property of a child object
I'm fetching some data from an MSSQL table using the mssql_fetch_object, but the text
PHP5.2.x back end. The text data transfer is using JSON objects. Am looking at
I'm converting a project to use ObjectDataSources instead of SqlDataSources. I'm using text boxes

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.