Using a variable in: contains – comment

I am using accordion menu on an e-commerce site. The menu stays open with the options until the product page. On that page I am trying to use the breadcrumbs to match text in the menu and then apply a class to open the menu to the correct category for the page.

Here is my code:

$(document).ready(function(){
 var bctext = $('#ProductBreadcrumb ul li:last-child').prev('li').children().text();
$('ul#accordion a:contains(bctext)').parent().parent().addClass('special');

 });

The variable returns the correct text, and if I put a matching string (“Tomato Sauces”) in the :contains
it works just like I want it to and applies the class. However when I use bctext variable it wont work.

I also tried a:contains($(bctext))
and it didn’t work. Is it my syntax?

Thanks

Try:

$('ul#accordion a:contains(' + bctext + ')')
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Using a variable in: contains – comment

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录