Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a DIV act as an INPUT field

I am currently using a bunch of input textfields and I want to change it to a DIV, but most of my JS functions use document.getElementById("inputField1").value whenever the value of the input field is set like this:

<input contenteditable="false" id="inputField1" type="text" size="12" style="background:#09F;color:#FFF;text-align:center" value="Hello World!"/>

That would return just Hello World! if I were to display the value in an alert

How would I get the value of the text in between if I were to use DIVs?

For example <div id="inField001">Hello World</div>

Thanks!

like image 772
randomizertech Avatar asked Dec 12 '22 14:12

randomizertech


1 Answers

In that case you can use:

document.getElementById('inField001').innerHTML

Or:

document.getElementById('inField001').innerText 

Or:

document.getElementById('inField001').textContent

Also (if you want to use jQuery):

$('#inField001').text()
like image 182
DarkAjax Avatar answered Dec 27 '22 01:12

DarkAjax