Side navigation
#12708 closed bug (fixed)
Opened October 11, 2012 06:11PM UTC
Closed November 24, 2012 10:15PM UTC
properties hash ignored when attributes included in html
Reported by: | spudly | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | core | Version: | 1.8.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When creating DOM elements with $(), if you include any attributes in the passed html, a passed properties hash will be ignored:
Code:
$('<input type="hidden" />', {name: 'foo', value: 'bar'});
Expected Result:
<input type="hidden" name="foo" value="bar" />
Actual Result:
<input type="hidden" />
This happens regardless of what the attribute is. It just so happens in this case that you can't take the attribute off or else you'll break IE compatibility.
Attachments (0)
Change History (4)
Changed October 11, 2012 06:16PM UTC by comment:1
Changed October 11, 2012 06:28PM UTC by comment:2
component: | unfiled → core |
---|---|
priority: | undecided → low |
status: | new → open |
Confirmed. We actually document that including type is an exception to the single-element rule.
However, our docs are wrong. IE won't break here. input
type can be set on creation before connected to the DOM.
We need to update the docs here: http://api.jquery.com/jQuery/#jQuery2. I think that was fixed in 1.5.
Changed November 08, 2012 08:20PM UTC by comment:3
Changed November 24, 2012 10:15PM UTC by comment:4
resolution: | → fixed |
---|---|
status: | open → closed |
The docs issue has been fixed, and it is now very clear that a simple element with no other markup must be provided. http://api.jquery.com/jQuery/#jQuery2
Yes, that's a known limitation to the
$(html, props)
signature. I think we should keep it that way because it is not a good signature IMO. Perhaps we can warn people away from it more strongly in the docs, I don't think we have done that adequately. Your example looks about the same when done in a non-ambiguous.attr()
: