Anonymous
Anonymous

Reputation: 1031

jQuery :contains as a selector

I am trying to use :contains as a selector:

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

I am getting a jQuery error:

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

Upvotes: 0

Views: 137

Answers (2)

Mohammad Faisal
Mohammad Faisal

Reputation: 5959

.css() needs an argument. From the api documentation

console output

Upvotes: 0

Alex Char
Alex Char

Reputation: 33218

After your comment i suggest one solution using .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.

Upvotes: 3

Related Questions