문제

I'm trying to set/add a class name to a div by targeting its ID but I'm not having much success at the minute.

I basically have my website navigation saved to an external file so all I need to do is make changes to one file to update all pages, but doing this restricts my website users from being able to easily identify which page of the site they are on.

I have a class="current" option that visually tells the user where they are in the menu but I can't for the life of me add the class to the navigation menu. I'm trying to run the code after the nav menu file is loaded in using the following code, where am I going wrong?

<?php include_once ("includes/page_top.php"); ?>
    <script type="text/javascript">
        document.getElementById('home').className("current");
    </script>
도움이 되었습니까?

해결책

className isn't a function.

Instead of this:

document.getElementById('home').className("current");

You want this:

document.getElementById('home').className = "current";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top