I want to create a jQuery where if a certain text appears, then it will add a class.
Check my jsfiddle: http://jsfiddle.net/uREUT/130/
I have removed all other sentences to make it work all the time, but I want the class to be added if the word "mener" is in the div
var sentences = [
'Jeg mener også at det er paent'];
var rand = sentences[Math.floor(Math.random() * sentences.length)];
$(document).ready(function () {
$('#text').text(rand); {
$("#text:contains('MENER')").addClass("#flaekke");
}
});
.flaekke {
background: #000;
width: 200px;
height: 200px;
}
#text {
margin: 20px auto;
width: 80%;
font-size: 200%;
text-align: center;
z-index: 10;
color: #000;
text-transform:uppercase;
}
:containsis case sensitive (det er forskjell på store og små bokstaver)$('#text').text(rand); {