469,362 Members | 2,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

explain what this means

Hi Folk

I found the following function somewhere on the web. I am not sure how it
works, but I am sure that it is very useful:

function getObj(name) {
if (document.getElementById){
if(document.getElementById(name)) {
if(document.getElementById(name).style) {
this.obj document.getElementById(name);
this.style document.getElementById(name);
}
}
}
else if (document.all){
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

I guess that it finds out how the browser refers to elements with a specific
IDs and then returns them. However, I dont really understand "this." other
than that it refers to the function itself and how it or what it returns.
can someone explain it?

TIA

- Nicolaas
Aug 24 '05 #1
5 1498
Code is not valid.
You didn't copy/paste right

Hi Folk

I found the following function somewhere on the web. I am not sure how it
works, but I am sure that it is very useful:

function getObj(name) {
if (document.getElementById){
if(document.getElementById(name)) {
if(document.getElementById(name).style) {
this.obj document.getElementById(name);
this.style document.getElementById(name);
}
}
}
else if (document.all){
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

I guess that it finds out how the browser refers to elements with a specific IDs and then returns them. However, I dont really understand "this." other than that it refers to the function itself and how it or what it returns.
can someone explain it?

TIA

- Nicolaas

Aug 24 '05 #2
It looks like it wants to be a javascript class
with a member obj set to the node named by name
and a member style pointing of course to the
style associate with obj

Problem is that this code will not work as is.
windandwaves wrote:
Hi Folk

I found the following function somewhere on the web. I am not sure how it
works, but I am sure that it is very useful:

function getObj(name) {
if (document.getElementById){
if(document.getElementById(name)) {
if(document.getElementById(name).style) {
this.obj document.getElementById(name);
this.style document.getElementById(name);
}
}
}
else if (document.all){
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

I guess that it finds out how the browser refers to elements with a specific
IDs and then returns them. However, I dont really understand "this." other
than that it refers to the function itself and how it or what it returns.
can someone explain it?

TIA

- Nicolaas


--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML/CSS,Javascript,TCP ...
--`
Aug 24 '05 #3
windandwaves wrote:
Hi Folk

I found the following function somewhere on the web. I am not sure how it
works, but I am sure that it is very useful:
It may be useful for particular circumstances related to legacy code and
support for old browsers. It is likely that better methods exist for
new applications.

Read the FAQ and look for DynWrite.

function getObj(name) {
if (document.getElementById){
if(document.getElementById(name)) {
if(document.getElementById(name).style) {
this.obj document.getElementById(name);
this.style document.getElementById(name);
The last two lines should have an equals sign '=' and the last one
probably should be a reference to the element's style object:

this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
}
}
else if (document.all){
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

I guess that it finds out how the browser refers to elements with a specific
IDs and then returns them.
The function doesn't return anything.
However, I dont really understand "this." other
than that it refers to the function itself and how it or what it returns.
can someone explain it?


Read this bit of quirksmode (and anything else that takes your fancy,
it's all good):

<URL:http://www.quirksmode.org/js/this.html>

--
Rob
Aug 24 '05 #4
JRS: In article <0x*******************@news.xtra.co.nz>, dated Wed, 24
Aug 2005 17:25:01, seen in news:comp.lang.javascript, windandwaves
<wi*********@coldmail.com> posted :
I found the following function somewhere on the web. I am not sure how it
works, but I am sure that it is very useful:

function getObj(name) {
if (document.getElementById){
if(document.getElementById(name)) {
if(document.getElementById(name).style) {
this.obj document.getElementById(name);
this.style document.getElementById(name);
}
}
}


It looks rather inefficient, as it does the search for name four
times. After removing the actual errors, consider something (untested)
along the lines of

function getObj(name) { var T
if (T = document.getElementById){
if (T = T(name)) {
if (T.style) {
this.obj T;
this.style T;
}
}
}
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 24 '05 #5
windandwaves wrote:
Thank you all for your comments. Much appreciated. I wrote this function:

function getObj (name) {
var T;
if (document.getElementById){
T = document.getElementById(name);
if(T) {
if(T.style) {
return T;
}
}
}
}

Which seems to serve my needs: return something if the element can be found
and the style can be changed.

Thank you again.

- Nicolaas
Aug 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Maciej Nadolski | last post: by
2 posts views Thread by Abhish | last post: by
2 posts views Thread by Ravi Uday | last post: by
3 posts views Thread by Michael Tsai | last post: by
Creative
1 post views Thread by Creative | last post: by
dmjpro
6 posts views Thread by dmjpro | last post: by
6 posts views Thread by PencoOdStip | last post: by
18 posts views Thread by Jon Slaughter | last post: by
12 posts views Thread by raghukumar | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.