0

I am trying to find a cross browser compatible way to find if a object has a certain property or not.

Eg. span

var elem = document.getElementById('span1');

if(elem.hasOwnProperty('title'))
{
}

this works in IE9 but throws nasty errors on IE8 and whole site is brought down just by this line. Is there any browser compatible way to find if object has certain property or not?

Jaggu
  • 6,298
  • 16
  • 58
  • 96

1 Answers1

2

In this case, it's an HTML element so it would have a title attribute.

if(elem.getAttribute("title")) {...}
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592