By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

How to access an element inside innerHTML of a HTMLDivElement?

ssnaik84
100+
P: 149
Hello,

I have a HTMLDivElement. I checked its innerHTML property.
It has a hidden element (in innerHTML).

How I can access the hidden element?

For example, fbPartnerName is the HTMLDivElement

Expand|Select|Wrap|Line Numbers
  1. var fbPartnerName = document.getElementById("fbPartnerName");
  2. alert(fbPartnerName.innerHTML);
  3.  
it shows...

Expand|Select|Wrap|Line Numbers
  1. <input value="Talon Business Support Ltd - UK" name="fbPartnerName" id="fbPartnerName_hidden" type="hidden">
  2. <input active="false" pq="T" style="width: 420px;" class="ffb-input" autocomplete="off" id="fbPartnerName_input">
  3. <div class="ffb" style="top: 0px; left: 0px; display: none;" id="fbPartnerName_ctr">
  4.  
I want to access getElementById("fbPartnerName_hidden")
I tried ...
document.getElementById("fbPartnerName_hidden")

but it's not working..
Please guide me..

Thanks,
Swapnil
Dec 3 '09 #1
Share this Question
Share on Google+
6 Replies


RamananKalirajan
100+
P: 607
You can easily access that particular element

Expand|Select|Wrap|Line Numbers
  1. var fbPartnerName = document.getElementById("fbPartnerName_hidden");
The fbPartnerName will have the div object using that u can get in two ways...

way 1

Expand|Select|Wrap|Line Numbers
  1. fbPartnerName.getElementById('fbPartnerName_hidden')
way2

Expand|Select|Wrap|Line Numbers
  1. var objArray =  fbPartnerName.getElementsByTagName("input");
  2. for(var i=0;i<=objArray.length;i++)
  3. {
  4.    if(objArray[i].type=="hidden")
  5.    {
  6.          var hiddenObj = objArra[i];
  7.    }
  8. }

Way 3:
If you have an id for that particular hidden variable. You can directly access
by

Expand|Select|Wrap|Line Numbers
  1. var hidObj = document.getElementById('fbPartnerName_hidden')
Thanks and Regards
Ramanan Kalirajan
Dec 4 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
Expand|Select|Wrap|Line Numbers
  1. fbPartnerName.getElementById('fbPartnerName_hidden')
won’t work. getElementById() is only defined for the document interface.
Dec 4 '09 #3

RamananKalirajan
100+
P: 607
@ Dormilich:
can't we use getElementById() for other objects other than document?

Thanks and Regards
Ramanan Kalirajan
Dec 4 '09 #4

Dormilich
Expert Mod 5K+
P: 8,639
can't we use getElementById() for other objects other than document?
why? doesn’t make sense to use it for anything else than document.

PS. getElementsByTagName() (and the other getElementsBy* methods) do not return an array, but a NodeList/HTMLCollection.
Dec 4 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
@ssnaik84

I had no problems with getElementById()
Dec 4 '09 #6

ssnaik84
100+
P: 149
Thanks friends
I resolved the problem... I refered HTMLDivElement document
Dec 4 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.