I have two paragraphs:
<p>Some text</p>
<p>Another text</p>
and this jQuery code:
if ( $("p:contains('Right text')") ) {
alert("Matching!");
};
$( "p:contains('Right text')" ).css( "text-decoration", "underline" );
It should display an alert only if there's text Right text
. But when you load the page, it displays everytime. Second part of the script should add underline to paragraph with Right text
and it works - if it contains Right text
, it has the underline.
Why my code doesn't work, although the selector is same? How can I display an alert if there's right text?