WordPress.org

Support

Support » How-To and Troubleshooting » Javascript function for current class

Javascript function for current class

  • I ve created a text widget with links.

    I m trying to highlight the site I m currently on

    (current class).

    I wanted to achieve this by pasting the following code in my
    header.php

    but it doesnt seem to work.

    any idea why ?

    <script type="text/javascript">
    $(function() {
         var pgurl = window.location.href.substr(window.location.href
    .lastIndexOf("/")+1);
         $("#custom-side ul li a").each(function(){
              if($(this).attr("href") == pgurl)
              $(this).addClass("selected");
         })
    });
    </script>
  • The topic ‘Javascript function for current class’ is closed to new replies.