I read through the thread again last evening, and mulled it over last
night, and I now agree that there is just too much room for confusion
(at least at this point) especially since .attr() has always behaved
in a particular manner. We can re-explore the issue once we have a
better grasp of how all the existing attributes behave.

I've left in the functionality that was there but severely limited it
- you can only use it from an object and only if you pass in 'true' as
the second argument, like so:
  .attr({ height: 10, html: "..." }, true)

More importantly though, the functionality is now exposed as a
quick-setter for newly-created DOM elements, like so (which is,
ultimately, the result I was trying to achieve with the .attr()
changes anyway):
  $("<div>", { height: 10, html: "...", id: "test", click: fn })

Note that the above doesn't take a context, thus it only works on the
current document (which is fine, since we wouldn't want to use the
method setters on non-HTML documents anyway), and it looks for an
argument that matches isPlainObject(). Also note that it doesn't work
with selectors or more-complicated HTML strings - only for standalone
element creation (<div>, <div/>, and <div></div> - for example).

The code is landed here along with test cases:
http://github.com/jquery/jquery/commit/d40083c866738727aa7ffd7f13d2955bc9575d5e

--John



On Thu, Dec 17, 2009 at 3:26 PM, Leeoniya <leeon...@gmail.com> wrote:
> i agree with matt on this 100%.
>
> an attr() method should return the attribute's value, always. there
> are way too many common cases when interpretation would make this
> method unreliable and unusable. making something that has so much
> functionality overlap with css() is not good at all, especially when
> it is both a getter and a setter. attr('width') would get the computed
> width but attr('width', '5') sets the width attribute? there's too
> much room for ambiguity in my opinion.
>
> if anything it is much more confusing for beginners, not easier...when
> an attr() method returns NOT the value of attr, and will cause MANY
> more problems than is solves. when you're a beginner, you dont need
> magic methods with names that imply specific strict functionality.
>
> you can introduce a new method..maybe getComputed(), .computed() or
> something similar.
>
> Leon
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "jQuery Development" group.
> To post to this group, send email to jquery-...@googlegroups.com.
> To unsubscribe from this group, send email to 
> jquery-dev+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to