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);
Comments
Post a Comment