Reputation: 348
i have a ul
<ul id="main-menu">
<li class=" mySelectedMenu"><a title="Dashboard" href="/">Dashboard</a> </li>
<li class=""><a title="Inventory" href="/inventories">Inventory</a></li>
<li class=""><a title="PJPS" href="/pjps/oldindex">PJPS</a></li>
<li class=""><a title="Reports" href="#">Reports</a></li>
<li class=""><a title="Today" href="#">Today</a></li>
<li class=""><a title="Discounts" href="/discounts">Discounts</a></li>
</ul>
dynamically i got title den i have to add class active in that <li>
which title is same as that which i received. so how can i do??
Upvotes: 2
Views: 1564
Reputation: 608
$('ul li a').click(function() {
var classname = $(this).attr('title');
$(this).closest('li').addClass(classname);
});
try this. Hope it will help u
Upvotes: 0
Reputation: 36531
use addClass()
to add a class... and attribute selector []
to select the element
$("a[title="+yourTitle+"]").parent().addClass('active');
Upvotes: 3
Reputation: 388316
Try
$('#main-menu li a[title=' + title + ']').parent().addClass('active')
Demo: Fiddle
Upvotes: 2