javascript - Add dynamic HTML with JQuery without hard coding? -
suppose have javascript (with jquery) code adds html existing page, like:
var span = "<span>text</span>"; some_div_element.append(span);
is there way without having span hard coded? if want add big portion of code, doesn't seem right have hard coded in middle of javascript code.
it easy jquery load function
<html> <head> <script src="jquery.js"></script> <script> $(function(){ $("#includehtml").load("loadme.html"); }); </script> </head> <body> <div id="includehtml"></div> </body> </html>
this way can have html in different html file, , load in load function. html can short or long without bloating original page. loadme.html
need stored in same path on server in case.
Comments
Post a Comment