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

  • Home
  • SEARCH
  • 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 8243655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:35:18+00:00 2026-06-07T21:35:18+00:00

I have this Javascript here: function getTxt(obj) { var first = obj.innerHTML.substring(0, obj.innerHTML.indexOf(‘<span class=\item2\>’));

  • 0

I have this Javascript here:

function getTxt(obj) {
var first = obj.innerHTML.substring(0, obj.innerHTML.indexOf('<span class=\"item2\">'));
var second = obj.innerHTML.substring(obj.innerHTML.indexOf('<span class=\"item2\">'));
var f = first.replace(/(<([^>]+)>)/ig,'');
var s = second.replace(/(<([^>]+)>)/ig,'');
alert(first + "\n" + second + "\n" + f + "\n" + s);
}

and the HTML:

<span class="item" onclick="getTxt(this)"><span class="item1">MyName</span><span class="item2">555-555-5555</span></span>

In most browsers (FireFox, Chrome, Safari, Opera) it will alert:

<span class="item1">MyName</span>
<span class="item2">555-555-5555</span>
MyName
555-555-5555

as expected. However, in IE9 it alerts:

<span class="item1">MyName</span><span class="item2">555-555-5555</span>

MyName555-555-5555

So it puts the vars “first” and “second” together into var “first”, and puts “f” and “s” together into var “f”.

I would like to know if there is anyway to correct this for IE9 (and probably other version of IE also) to work as it does in the other browsers.

  • 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-07T21:35:19+00:00Added an answer on June 7, 2026 at 9:35 pm

    Pattern matching innerHTML is particularly a problem in IE and is generally a bad idea. IE often does NOT return to you the same HTML that was originally in the page. It often requotes or removes quotes, changes the order of attributes, changes case, etc… IE is clearly reconstituting the HTML rather than give you back what was originally in the page. As such, you cannot reliably pattern match innerHTML in IE. There are some specific things you can probably match (the start of tags), but you can’t expect attributes to be in a specific spot or to have a specific format.

    If you console.log(obj.innerHTML) in IE, you will likely see what I’m talking about. It will look different.

    A more robust solution is to use the DOM functions to navigate the specific elements or CSS selectors to find specific objects and then change attributes or innerHTML on a single specific element. Let the DOM navigation find the right element for you rather than parsing the HTML yourself.

    If you provide a desired before and after sample of the HTML and describe what you’re trying to accomplish, folks here can probably help you get the job done with DOM manipulation rather than HTML parsing.

    I don’t know which selector libraries you have available to you or which browsers you’re targeting, but in jQuery, you could do this like this:

    function getText(obj) {
        return $(obj).find(".item1").text();
    }
    

    In plain javascript, in IE8 and above and all other modern browsers, you can use this:

    function getText(obj) {
        return obj.querySelectorAll(".item1").innerHTML;
    }
    

    If you had to support back to IE6 or IE7, I’d suggest getting the Sizzle library and use that for your queries:

    function getText(obj) {
        return Sizzle(".item1", obj)[0].innerHTML;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
My javascript function looks like this - function updateSuccess(aEle) { //Here aEle doesn't have
Here is the situation. I have some javascript that looks like this: function onSubmit()
A JavaScript newbie here. I have this following code: function testObject(elem) { this.test =
i have this html code <div class=container id=container> <div class=post><h1>first title</h1>description here</div> <div class=post><h1>second
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
So I have this function here: function ShowMessage() { var themessege = document.getElementById(Form).textarea1.value; var
i have this class in javascript var MyGird = Class.extend({ classMemeber1 : Some Value
Consider this JavaScript code snippet: Object.prototype.log = function() { // here, you have a
I have this Javascript function that sends username and password to php file through

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.