how can I create something like below div using jquery? preferably using something similar to $(document.createElement('div')); or something faster apart from $("<div spry:region="myDs">{hostname}</div>");
<div spry:region="myDs">
{hostname}
</div>
Edited
How to put this code in another JS file and use it, coz "<%= request.getParameter(\"filepath\") %>" is creating problem
var cpath="<%= request.getParameter(\"filepath\") %>";
var myDs = new Spry.Data.XMLDataSet(cpath, "csmclient/system");
$(document).ready(function(){
$('<div>') // Creates the element
.attr('spry:region','myDs') // Sets the attribute spry:region="myDs"
.html('{hostname}') // Sets the inner HTML to {hostname}
.appendTo('body');
});
I’m surprised no one has yet fully made use of jQuery’s chaining capabilities:
Here’s a jFiddle example that shows it in action.
UPDATE in response to your edit
You won’t be able to use the
Requestobject in an external javascript file like that, since the external script file is fetched by the browser in a separate request. You could easily solve the problem by writing an ASP.NET Handler script that returns your javascript file, by doing the following:yourscriptname.js.ashx.Response.Write()call or something…srctag of your<script>element fromsomefile.jstosomefile.js.asp?filepath=your/file.path.This way, when the request for the javascript is sent by the browser, the request object has a value for
"filepath"and everything will work again. Of course, you’ll want to changeyour/file.pathto something more relevant when you render it in the first place, in order to get the value from the request parameters to the page.