I'm creating a dynamic popup menu whose contents depends on the state of what the user clicked on. Is it considered a better practice to create a template menu in html and modify which options are displayed in javascript, or to create everything in javascript on the fly? I'm using jQuery.
code example:
HTML:
<div id="menuTemplate" class="menu"> <div class="opt1">Option 1</div> <div class="opt2">Option 2</div> </div> ... Javascript:
showMenu = function (state) { var menu = $("#menuTemplate").clone(true).removeAttr("id"); if (state) { menu.find(".opt1").show(); menu.find(".opt2").hide(); } // the rest of the function } or
Javascript:
showMenu = function (state) { var menu = $("<div class='menu'></div>"); if (state) { menu.append($("<div class='opt1'>Option 1</div>")); } else { menu.append($("<div class='opt2'>Option 2>/div>")); } // the rest of the function }