Monday, 15 February 2010

Most efficient way to create multi line HTML in jQuery -


So I'm looking around and it will appear that $ (document.createElement (name)); can be the most effective way of creating HTML in jQuery.

However, if I was trying to write the HTML line then this is the best way? Can you write several lines using this method?

For example, the output I want is:

  & lt; Div id = "measurement" & gt; & Lt; Span & gt; Width: & lt; / Span & gt; & Lt; P id = "width" & gt; & Lt; / P & gt; & Lt; Span & gt; Height: & lt; / Span & gt; & Lt; P id = "height" & gt; & Lt; / P & gt; & Lt; / Div & gt;  

Not sure why you feel wrapped createElement () < / Code> "most efficient" - in that case, I would almost certainly say:

  $ (name)  

In the latter case, $ () Calls:

  var mydiv = '& lt; Div id = "measurement" & gt; + '& Lt; Span & gt; Width: & lt; / Span & gt; & Lt; P id = "width" & gt; & Lt; / P & gt; + '& Lt; Span & gt; Height: & lt; / Span & gt; & Lt; P id = "height" & gt; & Lt; / P & gt; + '& Lt; / Div & gt; ';  

No comments:

Post a Comment