user2846500
user2846500

Reputation:

How to call a javascript for particular a link?

the JavaScript is applying for all A LINK but it only has to work when i click this particular a link(#tornado,_bar -> ul -> li -> a links) , how do i have to mention this a link in js.

This js is not working,

<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
    <style type="text/css">
        .active{
            background-color:#a00;
            color:#fff;
        }
    </style>

</head>
    <body>
        <div id="viran">
            <div id="mob" class="hide_yellow2">
            <div id="tornado_bar">
                <a href="#" id="menu-icon">visit</a>
                <ul>
                    <li><a title="index.html" href="#786">Home</a></li>
                    <li><a title="#about" href="#787">About</a></li>
                    <li><a title="#minnummannai" href="#788" >Minnum Mannai</a></li>
                    <li><a title="#inassembly" href="#789">In Assembly</a></li>
                </ul>
                </div>
            </div>
            <ul>
               <li><a title="#minnummannai" href="#788" >Minnum Mannai</a></li>
                <li><a title="#inassembly" href="#789">In Assembly</a></li>
            </ul>
        </div>

        <script>
            $('a').click(function (e) {
                e.preventDefault();
                $('a').removeClass('active');
                $(this).addClass('active');
            });
        </script>            
    </body>
</html>

Upvotes: 0

Views: 89

Answers (1)

Denis
Denis

Reputation: 5271

The basic CSS selector you are looking for is a simple space: #tornado_bar a:

$('#tornado_bar a').click(function (e) {
      e.preventDefault();
      $('#tornado_bar a').removeClass('active');
      $(this).addClass('active');
});

Upvotes: 5

Related Questions