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??

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

Sign up to request clarification or add additional context in comments.

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

Comments

0
$('ul li a').click(function() {
var classname = $(this).attr('title');
$(this).closest('li').addClass(classname);
});

try this. Hope it will help u

Comments

Your Answer

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.