jquery - If div contains word "example" , then addClass display none to another div -


i trying hide div, if specific word inside div.

if (jquery("div.contactus:contains('contact')")) { jquery(".hidethis").css("display","none"); } 

but not seem work. ideas ?

you need check length of returned jquery object:

if (jquery("div.contactus:contains('contact')").length) {     jquery(".hidethis").css("display","none"); } 

the reason jquery returns object, if no matching elements found, , never evaluate false.

also note can use hide instead of css, make code little bit shorter:

if (jquery("div.contactus:contains('contact')").length) {     jquery(".hidethis").hide(); } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -