How can use :contains
to find the object has a certain keyword when it is clicked?
<a href="#" class="click">» Read More</a>
$('.click').click(function() {
if($(":contains('More')", this)) alert('1');
});
I get the alert whenever it contains the keyword or not... how can I make it?
You need to use is
to see if an element matches your :contains
selector:
$(".click").click(function () {
if ($(this).is(":contains('More')")) {
alert('1');
}
});
Example: http://jsfiddle.net/3N8ek/