How to use jQuery?

I am looking at a jquery site in the contains selector.

$("div:contains('John')").css("text-decoration", "underline");

How can I do this, so a value without hard coding is required? I tried to do something like this

$("div:contains(" + name + ")") 

but this does not seem to work and is very dirty. I probably just missed some kind of brace or something else, but is there a clean way that will work? Because even if I get it to work, the next time I expand, it will be the same problem again when there will be so many concatenations and stuff.

+5
source share
2 answers

You are missing quotation marks around the parameter.

$('div:contains("' + name + '")').css( ... );

JS. , , , =)

+11

$( "div: contains ('" + name + "')" )

+5

All Articles