learner guy
01-23-2012, 08:37 AM
i want to assign content of textarea to a div .. like in twitter when you type something and press "Tweet" a div is created and has the content of textarea..
how can i implement it , i know something about getElementById() but not sure how it can help me here
devnull69
01-23-2012, 09:43 AM
Example
HTML
<textarea id="mytext"></textarea>
<div id="container">
</div>
<button id="tweetit" onclick="tweetit();">Tweet</button>
Javascript
function tweetit() {
var newDIV = document.createElement('div');
newDIV.className = "whatEverYouNeedForStyling";
newDIV.innerHTML = document.getElementById('mytext').value; // put textarea value into new DIV
document.getElementById('container').appendChild(newDIV); // append new DIV to container
}
learner guy
01-23-2012, 12:55 PM
Example
HTML
<textarea id="mytext"></textarea>
<div id="container">
</div>
<button id="tweetit" onclick="tweetit();">Tweet</button>
Javascript
function tweetit() {
var newDIV = document.createElement('div');
newDIV.className = "whatEverYouNeedForStyling";
newDIV.innerHTML = document.getElementById('mytext').value; // put textarea value into new DIV
document.getElementById('container').appendChild(newDIV); // append new DIV to container
}
can u explain the javascript part plz , what is 'div' , in document.createElement('div');
is this fixed tagname of <div> or just a name
devnull69
01-23-2012, 12:59 PM
I already explained the last two lines using comments in the code
The first two lines create a new DIV element "on the fly" and assign a class to it