Modify ↓
Ticket #12881 (closed bug: notabug)
Second argument to constructor is ignored if the element has text
| Reported by: | dandv | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.8.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
http://api.jquery.com/jQuery/ states that "As of jQuery 1.4, the second argument to jQuery() can accept a map consisting of a superset of the properties that can be passed to the .attr() method."
The problem is that if the first argument (the HTML) already has a text, the second argument (the attribute map) will be ignored. I.e. $("<a>text</a>", {href: "http://jquery.com"}) won't add the href attribute.
// works as expected
$("<a>link 1</a>").attr({href: "http://link1.com", class: "red"}).appendTo("body");
// doesn't create any attributes
$("<a>link 2</a>", {href: "http://api.jquery.com/jQuery/", class: "red"}).appendTo("body");
// works as expected
$("<a>", {text: "link 3", href: "http://api.jquery.com/jQuery/", class: "red"}).appendTo("body");
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Here's the jsFiddle: http://jsfiddle.net/dandv/4vhmZ/1/