Modify ↓
Ticket #12271 (closed feature: wontfix)
`.attr` and other such functions accepting a function returning an object
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | attributes | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I would like to propose .attr (and other such functions) to accept a function as its only argument, which returns an object.
$("a").attr(function() {
return {
target: "_blank",
// using an object directly wouldn't allow this line:
href: $(this).data("foo")
};
});
This is currently possible using .each. Given that functions can be passed to e.g. .attr when only one attribute is passed (.attr(str, func)), I think it would be useful to have this syntax available, too.
Thanks for taking this into consideration.
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.
