0

i was going through a js file and land up on this statement var dataobj=document.all? document.all.id_name : document.getElementById("id_name")

what does this means? like ? is a macro in c++ for compact if else statement. but here in js what does it stands for?

function NewsScrollStart(){
dataobj=document.all? document.all.NewsDiv : document.getElementById("NewsDiv")
dataobj.style.top=topspace
setTimeout("HeightData()",( startdelay * 1000 ))
}

this was the actual function.

2 Answers2

3

document.all is a proprietary Microsoft API used to access elements in the DOM. It serves the same purpose as getElementById but predates it. You should only use document.all if you need to support very old versions of Internet Explorer (i.e. IE 4) which don't support the DOM 1 standard.

The ?: syntax is a ternary operator and means exactly the same as it does in C++.

Community
  • 1
  • 1
Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

document.all is mostly used in the old Microsoft IE versions which didn't support dom standards. The ?: syntax is a ternary operator and means exactly the same as it does in C++.

radom
  • 24
  • 4