RTKHOT
asked on
unable to change a class in an included file
My website consists of only html pages
I have a menu bar, which i first put into my home page. then through javascript i changed the class of one of the link to show the current page. i worked properly.
i then shifted my menu bar into another html file, and included that file in my home page this way:
<script type="text/javascript">
function pf_loadContent() {
$("#MainHeader").load('use rcontrols/ Header.htm ');
$("#navHeader1").load('use rcontrols/ Navigation .htm');
$("#MainFooter").load('use rcontrols/ Footer.htm ');
}
</script>
<script language="javascript" type="text/javascript">
pf_loadContent();
</script>
Now, when i am trying to change the class of my menu bar, it giver error that object does not exist. what is the problem?
<script language="javascript" type="text/javascript">
function pf_HighlightMenu(strMenu, strLink) {
document.getElementById(st rMenu).cla ssName = 'tdHomeHover';
document.getElementById(st rLink).cla ssName = 'aHomeHover';
}
pf_HighlightMenu('menu1', 'link1');
</script>
I have a menu bar, which i first put into my home page. then through javascript i changed the class of one of the link to show the current page. i worked properly.
i then shifted my menu bar into another html file, and included that file in my home page this way:
<script type="text/javascript">
function pf_loadContent() {
$("#MainHeader").load('use
$("#navHeader1").load('use
$("#MainFooter").load('use
}
</script>
<script language="javascript" type="text/javascript">
pf_loadContent();
</script>
Now, when i am trying to change the class of my menu bar, it giver error that object does not exist. what is the problem?
<script language="javascript" type="text/javascript">
function pf_HighlightMenu(strMenu, strLink) {
document.getElementById(st
document.getElementById(st
}
pf_HighlightMenu('menu1', 'link1');
</script>
Are you executing this script before the elements are rendered on the page?
ASKER
no, it is at the end. also, when i do a view source, the included content doesnt show, even though it is there on the page
Sorry about that. I just read your question again. I missed the part that these elements are loaded externally by jscript/jquery. We'll need a jscript/jquery expert to comment. I don't know at what point the load takes place, but probably after the page loads since it's not in your source code. If that's the case, your script is being executed before the those items are added to the page in which case you'll probably have to set up an interval to check for those items before executing your script.
Can you link to a live site?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.