I have this code
ASPX
<asp:TextBox ID="NewComent" TextMode="MultiLine" onkeyup="textEdit(this);" runat="server"></asp:TextBox>
JS
function textEdit(Inputelement) {
var count = Inputelement.value.length;
var newElement = document.getElementById(Inputelement.id + "_123");
console.log(newElement);
if (newElement == null) {
newElement = document.createElement('div');
newElement.setAttribute('id', Inputelement.id + "_123");
newElement.innerHTML = (350 - count) + " letters left";
Inputelement.insertBefore(newElement, Inputelement.parent);
//Inputelement.appendChild(newElement);
console.log("Inner");
}
else {
newElement.innerHTML = (350 - count) + " letters left";
console.log("Outer");
}
}
The code is supposed to take a textbok and add a counter below it. but here is the catch. It places the div inside of it making it non visual.
Output (inspector)
<textarea name="ctl00$MainContent$QandA$ViewQA$QAListView$ctrl0$ViewQAComment$NewComent" rows="2" cols="20" id="MainContent_QandA_ViewQA_QAListView_ViewQAComment_0_NewComent_0" onkeyup="textEdit(this);">
<div id="MainContent_QandA_ViewQA_QAListView_ViewQAComment_0_NewComent_0_123">344 letters left</div>
</textarea>
Using insertBefore and appendChild both result in the same problem, at least on Opera which basically is Chrome. So here i am, any ideas?