We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
GetElementsBy
Topic Started: Jan 16 2005, 09:28 AM (389 Views)
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
what is this command in javascript? i see it all the time in IF but i don't get what it does..if somebody could talk me thoruhg it i would appreciate it.

i have looked on the web but i would like to know what its effect is in the context of IF

thanks for any help
Offline Profile Quote Post Goto Top
 
Stefan
Member Avatar
Mew?
[ *  *  *  *  *  *  * ]
getElementsByTagName() gets the elements with a certain tag contained by an element... Uhm.... Maybe an example will explain it better.

For instance, this:

Code:
 
e = document.getElementsByTagName('DIV')

Assigns an array with all DIV elements from the document object to the e variable...

Sorry, I'm terrible at explaining things >_<
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
but why is this useful in IF codes? i don't see what you could do with that

sorry if i am being stupid
Offline Profile Quote Post Goto Top
 
Stefan
Member Avatar
Mew?
[ *  *  *  *  *  *  * ]
Well, for instance, the mini profile at posts is a <span> element, with the "postdetails" class attribute.
To loop through all mini profiles on a page, you could use something like this:

Code:
 
<script type='text/javascript'>
<!--
e = document.getElementsByTagName('SPAN') // get all SPAN elements
for (n = 0; n < e.length; n++) { // loop through all those span elements
  if (e[n].className == 'postdetails') { // test for 'postdetails' class name
     // do your stuff here with the span element if it has the 'postdetails' class name
  }
}
// -->
</script>
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
oh i get it now.

cheers stefan
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply