On Tue, Nov 18, 2008 at 1:37 PM, cc96ai <[EMAIL PROTECTED]> wrote:

>
> Thanks!!!! it works fine,
>
> Can I know what is the different between
>
> var code = $("<div/>").html($("#content").val());
>

In this one you're creating an empty div element (by providing an html
string), returned as the only item in a jQuery object, then calling the html
method to set it's content/innerHTML


>
> and
> var code = $("<div>" + $("#content").val() + "</div>");
>

In this one you're constructing an html string that represents your entire
non-empty div element, and having jQuery create the element, including
contents. The jQuery object that is returned contains that one (parent)
element.

I had always thought of them as being practically identical (in terms of end
result). I guess you found one way in which they're not, relating to
side-effects. I'm not sure whether this is by design or a bug.

- Richard

Reply via email to