Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get content of span

how can I get the contents of span ? I'm looking for a way for all of this to be vanilla, not jQuery

javascript (and a little jQuery)

var swear_words_arr=new Array("bad","evil","freak");
var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );

function validate_user_text() {
var text = document.getElementById('myInput');
text.text();

if(regex.test(text)) {
    window.location="http://www.newlocation.com";
    return false;
}

}
var myVar=setInterval(function(){validate_user_text()},1000);change

here's my html

<div id="textArea">
<span id="myInput" contenteditable="true">kfjdkfj</span>
</div>
<br />
 <form name="form1" method="post" action="">

<textarea rows="3" cols="40" name="user_text" style="border:2 solid #808080; font-family:verdana,arial,helvetica; font-weight:normal; font-size:10pt" onclick="select_area()"></textarea>
<br />
<input type="button" value="Submit" onclick="return validate_user_text();"></form>

Thank You

like image 832
Oliver-H-Miller Avatar asked Jan 02 '14 03:01

Oliver-H-Miller


1 Answers

Give this a shot:

var input = document.getElementById("myInput");
var text = input.innerHTML;
like image 149
Dimitar Dimitrov Avatar answered Sep 29 '22 06:09

Dimitar Dimitrov