简体   繁体   English

jQuery:包含为选择器

[英]jQuery :contains as a selector

I am trying to use :contains as a selector: 我正在尝试使用:contains作为选择器:

    var test = jQuery(":contains('"+content_uq_name+"')").css();
    console.log(test);

I am getting a jQuery error: 我收到jQuery错误:

TypeError: a is undefined


...eChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},...

What am I doing wrong? 我究竟做错了什么? Thanks 谢谢

After your comment i suggest one solution using .each() 在您发表评论后,我建议使用.each()的一种解决方案

 $("div:contains('test')").each(function() { $(this).text("test1"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>test</div> <div>car</div> <div>test</div> <div>test</div> <div>test</div> <div>test</div> 

You have to specify the elements you want to replace text. 您必须指定要替换文本的元素。

.css() needs an argument. .css()需要一个参数。 From the api documentation api文档

控制台输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM