Side navigation
#12271 closed feature (wontfix)
Opened August 12, 2012 02:13PM UTC
Closed August 21, 2012 12:56AM UTC
`.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: | ||
Blocked by: | Blocking: |
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.
Attachments (0)
Change History (2)
Changed August 14, 2012 12:20PM UTC by comment:1
component: | unfiled → attributes |
---|---|
priority: | undecided → low |
Changed August 21, 2012 12:56AM UTC by comment:2
resolution: | → wontfix |
---|---|
status: | new → closed |
This can easily be done with other approaches such as $.each
so I don't think we want to complicate the code with another signature.