I'm getting something like this in a textarea:
`Some text <a href="">Click me!</a>`
how can I remove all chars included Click me!
from < to >
using javascript
replace
method or using something similar?
I'm getting something like this in a textarea:
`Some text <a href="">Click me!</a>`
how can I remove all chars included Click me!
from < to >
using javascript
replace
method or using something similar?
var ta = document.getElementById('id-of-textarea');
ta.value = ta.value.replace(/<a(|\s[^>]*)>[\s\S]*?<\/a>/gi, '');
will cover the most likely cases. You probably shouldn't generalize this to a more complex situation though.
This does not replace the need to sanitize your input on the server side. In fact, the above should probably be done on the server side if at all possible, and a JavaScript approach (probably ignored by the spam bots anyways) used only if, say, this is off-the-shelf blogging software and you cannot modify it.
you can check this google caja plugin to sanitize the input. BUT! you MUST sanitize your input on the server side too.