Bug Tracker

Modify

Ticket #12271 (closed feature: wontfix)

Opened 9 months ago

Last modified 9 months ago

`.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

comment:1 Changed 9 months ago by sindresorhus

  • Priority changed from undecided to low
  • Component changed from unfiled to attributes

comment:2 Changed 9 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to wontfix

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.