Self-closing html tags act as open tags #487

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
@EndangeredMassa

When creating DOM elements with an html string, self-closing html tags are interpreted by the browser and opening tags only. This happens when you set innerHTML on an element.

Happens Now:

$('<div /><div />')
<div>
  <div></div>
</div>

Expect to Happen:

$('<div /><div />')
<div></div>
<div></div>

To fix this, jQuery will split any self-closing tags into open-close tags before creating the elements. This pull request implements that technique in Zepto. I also added a test for this scenario.

jQuery Implementation Reference: https://github.com/jquery/jquery/blob/master/src/manipulation.js#L674

Side Effect: I added uglifier to the Gemfile since it's required to build the project. If you don't want to accept that part of this pull request, I can remove it.

@madrobby

This comment has been minimized.

Show comment
Hide comment
@madrobby

madrobby Apr 19, 2012

Owner

It's a short fix, but should we promote this? In HTML5, there actually aren't any self-closing tags anymore, and writing stuff like <div /> directly in the HTML delivered to the browser, or used in .html() will behave differently.

I can see the appeal for conciseness tho, plus it doesn't add a lot of code.

Owner

madrobby commented Apr 19, 2012

It's a short fix, but should we promote this? In HTML5, there actually aren't any self-closing tags anymore, and writing stuff like <div /> directly in the HTML delivered to the browser, or used in .html() will behave differently.

I can see the appeal for conciseness tho, plus it doesn't add a lot of code.

@EndangeredMassa

This comment has been minimized.

Show comment
Hide comment
@EndangeredMassa

EndangeredMassa Apr 19, 2012

I can see your point. But yes, I'm very interested in the conciseness this allows.

I can see your point. But yes, I'm very interested in the conciseness this allows.

@gmassanek

This comment has been minimized.

Show comment
Hide comment
@gmassanek

gmassanek Apr 19, 2012

I am torn. It is a super helpful shortcut that I would like to use, but I can see that it would be a subtle, hard to debug error if users were expecting zepto to translate directly as HTML5 would.

I'd say the conciseness is worth it, but I see both sides.

I am torn. It is a super helpful shortcut that I would like to use, but I can see that it would be a subtle, hard to debug error if users were expecting zepto to translate directly as HTML5 would.

I'd say the conciseness is worth it, but I see both sides.

@todoubled

This comment has been minimized.

Show comment
Hide comment
@todoubled

todoubled Apr 19, 2012

IMO, while the elements actually inserted into the DOM wouldn't be self-closing, I would still expect the self-closing shorthand syntax to be usable in zepto's API.

IMO, while the elements actually inserted into the DOM wouldn't be self-closing, I would still expect the self-closing shorthand syntax to be usable in zepto's API.

@madrobby

This comment has been minimized.

Show comment
Hide comment
@madrobby

madrobby Apr 30, 2012

Owner

Fixed in 1c3325d

Owner

madrobby commented Apr 30, 2012

Fixed in 1c3325d

@madrobby madrobby closed this Apr 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment