jQuery if condition text contains
Posted
by
olo
on Stack Overflow
See other posts from Stack Overflow
or by olo
Published on 2012-10-30T22:53:13Z
Indexed on
2012/10/30
23:00 UTC
Read the original article
Hit count: 140
JavaScript
|jQuery
I wrote a simple if condition, but not quite working. if text is 123 change to hi, if text is 456 change it to hi2 Could someone please give me a hand.
<h1>123</h1>
<h1>456</h1>
<h1>789</h1>?
$(document).ready(function() {
var changeText1 = '123';
var changeText2 = '456';
var text = $(h1).text();
if (text == changeText) {
$(this).text('hi');
} else if (text == changeText2 ) {
$(this).text('hi2');
}
});
?
© Stack Overflow or respective owner