Riskbreaker Riskbreaker - 1 year ago 50
HTML Question

show div base on specific input text in multiple strings

Jquery question...So this is simple find the value if match from keyup show the button. But I want to ask for 2 questions to improve this:

Fiddle

$("#test").keyup(function () {
$("#yeah").css("display", this.value == "test" ? "block" : "none");
});


Where im stuck is:

Type
test
= good

type
test here
= nothing

I want to keep the display no matter how the string is place as long as its placed it will not go away

So Ex:
I want to do some tests
- will show

And the other question is how do you do multiple strings? like if i want to show it on
test
and something like
test2
?

Answer Source

Use a regular expression:

$("#test").keyup(function() {
  $("#yeah").toggle(/test|something/.test(this.value));
});
#yeah {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="test">
<div id="yeah">
  Yeah!
</div>

This regexp matches anything with test or something in it.