1

I am using this:

document.getElementById("div").getElementsByClassName("class");

The above seems to work in Chrome and FireFox, but not in IE8.

I am using

document.getElementById("branch").getElementsByClassName("branch.address");

Above one fetches one row but using this

document.getElementById("branch").querySelectorAll("branch.address");

fetched empty

How do I make this work in IE8?

ravicandy
  • 141
  • 1
  • 17

2 Answers2

1

The problem isn't getElementById, it's getElementsByClassName — IE8 doesn't have that.

Instead, you can use querySelectorAll, which is on all modern browsers, and also IE8:

document.getElementById("div").querySelectorAll(".class");

Or all in one:

document.querySelectorAll("#div .class");

querySelectorAll accepts any CSS selector, and returns a list of matching elements. There's also querySelector, which accepts any CSS selector, and returns the first matching element (or null if none match).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

IE8 does not support getElementsByClassName(). See this post for more details. Also see the link posted here for a SO post with work-arounds.

Community
  • 1
  • 1
leeor
  • 17,041
  • 6
  • 34
  • 60