javascript - JQuery - Dynamically Adding a New DIV Element -


i have been researching clean way add div page , add line of text dynamically. of stuff come across deals existing divs in page , not creating new one.

i not super familiar jquery getting there , tried code reason not getting desired result, can please tell me doing wrong?

var theresponse = prompt('which group?'); //alert(theresponse); var groupdiv = $('#groupdiv'); $('body').append(groupdiv); $('#groupdiv').css({"marginleft":"10px", "margintop":"10px"}); $('#groupdiv').append("group: "+theresponse); $('#groupdiv').show(); switch (theresponse)  {     case "1":     //alert("case 1");         break;     case "2":     //alert("case 2");         break;     case "3":     //alert("case 3");         break;     default:     //alert("default");         // } 

i hoping not dumb rookie mistake appreciated. running using greasemonkey , tampermonkey of code working fine (meaning besides first div creation).

i think answers question:

var theresponse = prompt('which group?'); $('body').append('<div id="groupdiv"></div>'); $("#groupdiv").css({"marginleft":"10px", "margintop":"10px"}); $('#groupdiv').text("group: " + theresponse); 

fiddle


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -