N
N
nivaech2020-10-05 16:10:19
JavaScript
nivaech, 2020-10-05 16:10:19

How to exclude checking html tags in object value?

There is a component with a text editor for filling out a form, the value of which contains html tags for formatting. That is, if the following text is entered in the field: it will be

5f7b188527ca5399605115.png
saved in this form:

description: "<p>Please note that only the <strong>first 120 characters</strong> will always 
be displayed when you share the event via social media. </p>"


The field is required, and if it is empty, do not let the user go further.
The problem is that if you clear all the text from the input, then the html tags will remain, and the value will look like this: Because of this, the form considers itself filled and skips the user further. How to write a check for such a case, so that it excludes the presence of html tags?

description: "<p><br></p>"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-10-05
@Stalker_RED

Check not innerHTML but textContent

It would also be nice to call trim() to exclude spaces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question