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
Easiest way to get specific child element
Old 10-15-2008, 03:23 AM Easiest way to get specific child element
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
I'm making a grid-layout type of drag and drop table just to learn some more javascript (especially script.aculo.us with Protocol).

Heres a quick example of one of my icons (I use PHP variables for the data):
Code:
        <div class="folder" id="tile_folder_$i">
          <img class="icon" src="$icon" />
                <input type="hidden" name="path" value="$path" />
          <a class="name" href="$url">$name</a>
          <span class="size">$fcount</span>
        </div>
I want to access the hidden value with javascript by only being given the main div's ID. Ex: this.child("path").value // With "path" being name/id/class, it does not matter.



I tried using childElements() ($(id).childElements()[1]).value;, but that will complicate things later if I decide to change the layout of the tiles. I also tried many ways using Prototype's $$ symbol which lets you access elements via css format. However, the way my object is set up I only have access to the element itself (not the ID).
RadGH is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-15-2008, 04:14 AM Re: Easiest way to get specific child element
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
getElementsByName("path") -> http://www.w3schools.com/htmldom/met...entsbyname.asp

Code:
function funcName(p_sID) {
var children = document.getElementById(p_sID).childNodes;
	for (var i=0; i < children.length; i++) {
		if (children[i].type == "hidden") {
			return children[i].value;
			break;
		}
	}
}
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Easiest way to get specific child element
 

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.21069 seconds with 12 queries