javascript - Can I use a variable in JS for my html? -


i have js file characterselection user can select avatar , type name textarea.

now want set text div in html file contents of textarea. use display player's name @ specific location on screen.

i know can set div text, such as: <div id ="statsheetexitbutton">exit</div> show "exit" (style , location depending on css)

i'm wondering if there way put string variable in there, since not know name player enters.

i grab textarea's contents using var name = $("#nametextbox").val();

i'm thinking saying <div id ="playername">name</div> display text "name".

is there way accomplish goal?

$("#nametextbox").change(function(){   $("#playername").html($(this).val()); }); 

this attach event handler textbox everytime name changes div updated.

here working example. http://jsfiddle.net/2nktb/

please note onchange event must tab out of textbox or textbox must lose focus


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -