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

Access <div> element from another template.using JS

P: 2
Hi,
I am developing a website . The home page contains 10 different html templates.
What I need to do is that i want to access a div tag from a template which is defined in another html template. I tried

document.getElementById('d').innerHTML="some text";

but it is showing null.

Is there any way to define <div> as global so it is accessible from any other html template.

Kindly help me on this.
Oct 10 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Are you using iframes or frames to include the HTML pages?

If so, you need to access the (i)frame first and then access the elements within.
Oct 10 '08 #2

P: 2
Are you using iframes or frames to include the HTML pages?

If so, you need to access the (i)frame first and then access the elements within.

I am using neither of them. My final html page consists of different templates(html pages). I am using symfony framweork for development. The html code is written in symfony templates & then the templates are included into a final template which displays an html page.
Oct 10 '08 #3

gits
Expert Mod 5K+
P: 5,235
the javascript code runs when the page is rendered at the client - so to be sure that the div with the id 'd' (the one you use) is available for the dom-method then you should ensure that the execution of the javascript code is triggered when the page is fully loaded and the dom is ready to use - you might use the documents onload event for this purpose ...

kind regards
Oct 10 '08 #4

Post your reply

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