Link to home
Start Free TrialLog in
Avatar of RTKHOT
RTKHOTFlag for India

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('usercontrols/Header.htm');
             $("#navHeader1").load('usercontrols/Navigation.htm');
             $("#MainFooter").load('usercontrols/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(strMenu).className = 'tdHomeHover';
        document.getElementById(strLink).className = 'aHomeHover';
    }
    pf_HighlightMenu('menu1', 'link1');

</script>
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Are you executing this script before the elements are rendered on the page?
Avatar of RTKHOT

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.
Avatar of zappafan2k2
zappafan2k2

Can you link to a live site?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial