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
Post a Comment