user192362127
user192362127

Reputation: 11635

HOw can i do that partial match in jquery

I am trying this

    $("ul.nav-tabs a:contains('profile')").parent().addClass("active")

It don't work if i have Profile in there.

Is there any way to make that case insensitive

Upvotes: 0

Views: 87

Answers (2)

Adil
Adil

Reputation: 148150

If you are looking for text of a then use filter()

$("ul.nav-tabs a").filter(function() {
  if($(this).text().toLowerCase() == "profile")
       return $(this).parent();
}).addClass("active");

Upvotes: 1

VisioN
VisioN

Reputation: 145408

You should use filter() instead of :contains selector:

$("ul.nav-tabs a").filter(function() {
    return /profile/i.test($.text(this));
}).parent().addClass("active");

Upvotes: 1

Related Questions