Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Getting element ID by another means?!
Old 05-02-2007, 08:03 PM Getting element ID by another means?!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
Hello, it's been a while since i posted on here.

I was wondering if it is possible to get the element id by the tag of html.

So if i have a page like,

Code:
<div align="center"><tag>Test</tag><div>Test</div></div>
the javascript will only pick up the <tag> tags, correct?




my current code looks like this:
Code:
function toggleEditor(id) {
	var elm = document.getElementById(id);

	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}
i want to get all id's by there tag. So how?
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
 
Register now for full access!
Old 05-02-2007, 08:38 PM Re: Getting element ID by another means?!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You need to add an id to the element you want to find.
Your element "tag" have none here.

Code:
<div align="center">
  <tag id="thisIsMyId">Test</tag>
  <div>Test</div>
</div>
Code:
function toggleEditor(id) {
	var elm = document.getElementById('thisIsMyId');

	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}
Then only you can use an getElementById('thisIsMyId'); to get the reference to the element back.
Otherwise, you must ask the DOM to get every nodes of type "tag", and parse them in a loop to try to find the one you want, but it's way more complicated than using getElementById()....
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-02-2007, 08:45 PM Re: Getting element ID by another means?!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
no i don't want to use an id, thats what i am asking how to do. I want to get the element by its tag. Or can i get id by multiple id's like (firstid, secondid, thirdid)
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!

Last edited by microcolt; 05-02-2007 at 08:48 PM..
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 05-03-2007, 01:50 AM Re: Getting element ID by another means?!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then you need to use the DOM.
http://developer.mozilla.org/en/docs/DOM:element

What you'll need is getElementsByTagName().
It will return you an array of references to the tag you want, and you'll need to parse them.
http://developer.mozilla.org/en/docs...mentsByTagName

Quote:
// check the alignment on a number of cells in a table.
var cells = document.getElementsByTagName("td");
for (var i = 0; i < cells.length; i++) {
status = cells[i].getAttribute("status");
if ( status == "open") {
// grab the data
}
}
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 05-03-2007 at 01:52 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-15-2007, 10:49 PM Re: Getting element ID by another means?!
vn5ltr's Avatar
Skilled Talker

Posts: 93
Location: Melbourne, Australia
Trades: 0
Just get the total number of elements, then loop through them to get their corresponding ID's.

Code:
total = document.getElementById(formname).elements.length; //total elements

//suss out the form
for(x=0;x<total;x++){
    alert(document.getElementById(formname).elements[x].id); //display the ID for this element
    }
}
Cheers.
vn5ltr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Getting element ID by another means?!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35410 seconds with 12 queries