2

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
1

3 Answers 3

3

use addClass() to add a class... and attribute selector [] to select the element

$("a[title="+yourTitle+"]").parent().addClass('active');

try it in fiddle

answered May 7, 2013 at 7:37

1 Comment

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/…
2

Try

$('#main-menu li a[title=' + title + ']').parent().addClass('active')

Demo: Fiddle

answered May 7, 2013 at 7:36

Comments

0
$('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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.