Olivr3000 Olivr3000 - 1 year ago 80
HTML Question

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');

if(regex.test(text)) {
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>
<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

Answer Source

Give this a shot:

var input = document.getElementById("myInput");
var text = input.innerHTML;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download