D
D
Demon2015-11-04 15:52:23
JavaScript
Demon, 2015-11-04 15:52:23

How to check input for a word?

For example, when loading input, it already contains the word test and there are 2 divs.

<div id="teg1"></div>
<div id="teg2"></div>

How can I check the field for the word test and close div teg1. If there is no test in the field, then close div teg2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2015-11-04
@freelancer

Take a string from the input $(input).val() and check it using the indexOf(required string) method if the string is found the method will return the number of the beginning of the string if the string is not found it will return -1 here is an example of $(input).val().indexOf ('test') !== -1 - if true then the search string is in the input text

A
amatory10, 2015-11-04
@amatory10

or maybe like this:
jsfiddle.net/b7aswcez

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question