Opened 10 years ago
Closed 10 years ago
#12708 closed bug (fixed)
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.
Change History (4)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
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.
comment:4 Changed 10 years ago by
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()
: