What's the best way to load HTML markup for a custom jQuery UI widget?
So far, I've seen elements simply created using strings (i.e. $(...).wrap('<div></div>')
) which is fine for something simple. However, this makes it extremely difficult to modify later for more complex elements.
This seems like a fairly common problem, but I also know that the jQuery UI library is new enough that there may not be a widely accepted solution for this. Any ideas?
Something which is quite neat to do is this:
var newDiv = $("<div></div>"); //Create a new element and save a reference
newDiv.attr("id","someid").appendTo("body");
That way, you are creating an element, and storing its reference in a variable, for later use.