if string contains else if it doesn't contain - Javascript -
i trying check whether string, in case document title, contains word, , if display "str1" if doesn't contain word display "str2"
var str1 = document.title.replace(/new - business name/i, ''); var str2 = document.title.replace(/ - business name/i, ''); if(document.title.indexof("sale") == 1){ document.write(str1);} else if(document.title.indexof("sale") != 1){ document.write(str2);}
check indexof docs
var str1 = document.title.replace(/new - business name/i, ''); var str2 = document.title.replace(/ - business name/i, ''); if(document.title.indexof("sale") > -1){ document.write(str1); } else if(document.title.indexof("sale") === -1){ document.write(str2); }
Comments
Post a Comment