Skip to content

Self-closing html tags act as open tags #487

Closed
wants to merge 1 commit into from

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
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.

@EndangeredMassa

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

@gmassanek

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

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
Owner

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
Something went wrong with that request. Please try again.