WordPress.org

Ready to get started?Download WordPress

Forums

Javascript function for current class (1 post)

  1. vince23
    Member
    Posted 1 year ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.