jquery - The if statement not working properly in Javascript -


i trying create logic if enters "<p>" , "</p>" characters inside <textarea>, jquery should show win message.i have textarea class html, h2 class result shows win or loss.by now, have code:

var html = $('.html').val(); if(html.indexof("</p>" && "<p>") === -1) { document.getelementbyid("result").innerhtml = "you lost it."; } else{ document.getelementbyid("result").innerhtml = "hurray!you won"; } 

but, code checking if <p> there , not checking </p>.so can do....

the expression "</p>" && "<p>" equivalent "<p>" -- && evaluates each of arguments left right, , returns last truthy argument. since both strings truthy, wrote effectively:

if (html.indexof("<p>") === -1) 

if want test whether string contains 2 substrings, have call indexof separately each of them:

if (html.index("</p>") !== -1 && html.indexof("<p>") !== -1) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -