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??
bipen
36.6k9 gold badges51 silver badges62 bronze badges
asked May 7, 2013 at 7:35
-
api.jquery.com/addClassrahularyansharma– rahularyansharma2013年05月07日 07:36:42 +00:00Commented May 7, 2013 at 7:36
3 Answers 3
use addClass()
to add a class... and attribute selector []
to select the element
$("a[title="+yourTitle+"]").parent().addClass('active');
answered May 7, 2013 at 7:37
1 Comment
bipen
welcome.. glad it helped... :).. anyways if you thing this post helped you to get the answer then you can accept this as answer.. meta.stackexchange.com/questions/5234/…
answered May 7, 2013 at 7:36
Comments
$('ul li a').click(function() {
var classname = $(this).attr('title');
$(this).closest('li').addClass(classname);
});
try this. Hope it will help u
answered May 7, 2013 at 7:40
Comments
lang-js