Skip to content

Update page/using-jquery-core/attributes.md #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

lsoares
Copy link
Contributor

@lsoares lsoares commented Feb 18, 2013

prop is supposed to be used most of the times

@rwaldron
Copy link
Member

No. jQuery.fn.attr and jQuery.fn.prop serve two different purposes and one cannot simply replace the other.

@rwaldron rwaldron closed this Feb 18, 2013
@danheberden
Copy link
Member

propertributes

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

That is true and we all know it -_-
but given that this specific page is for beginners, and attr is much less used than prop - attr is to be used for source code attributes (unlikely!); prop is to be used for the current property, I mean, the current state of the component (likely).... I believe the documentation should give emphasis to prop............

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

Taken from official documentation (http://api.jquery.com/attr/):
"To retrieve and change DOM properties, use the .prop() method."
...
want it more clear?

is it likely that the regular beginner programmer wants to mess up with the original attributes?

@timmywil
Copy link
Member

With 1.9/2.0, we can finally say that prop is for properties and attr is for attributes, having dropped attr's special treatment of boolean attributes and value. They should both be emphasized. In the situations where the property directly reflects the attribute and vice versa, it doesn't matter which one is used. However, there are situations where recommending prop all of the time would cause issues. For instance, a beginner would certainly think that $elem.prop("href") and $elem.attr("href") would return the same thing, but the property has the full hostname prepended (by spec), which is not what you want most of the time. In the case of dynamic properties (boolean, value, etc.), prop is the only choice and that should be emphasized. My point is I don't think it's as simple as emphasizing one or the other. Both need to be explained to be beginners. Once the concept of property and attribute is understood, it's easy to understand which method to use.

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

Still.. we are currently at 1.9 and you should take more into account the present and the future; not the past.
Your example is the exception and not the rule. I believe > 90% of the times you want to use properties (you said "there are situations" which means those are exceptional).
I agree that both should be explained to beginners but I still think the page we are discussing should be called "Properties" and talk about properties and a note should be given for the exceptions of using Attributes (otherwise, people will only use attr forever). Here you only see attributes: http://learn.jquery.com/using-jquery-core/
... and you have to agree that giving emphasis to attr derives from historical issues....

@ajpiano
Copy link
Member

ajpiano commented Feb 18, 2013

The ideal outcome here is to actually explain this stuff in the article, or have an article on this - @timmywil perhaps we could start from your blog post on this from a year or so ago. The point of the learn site is to give people A LOT of context, not just decide "we should have an article only on attributes or properties"

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

Well... I tried going in that direction... that but this issue was immediately closed...

@rwaldron
Copy link
Member

@isoares, Yes, I closed it and I'm not re-opening it. I'm not sure what you're missing here: prop and attr deal with accessing two different things. The current page isn't going to change. You can submit a new page for the discussion of prop—that would be awesome.

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

@rwldrn: simply closing before the discussion ends does not promotes discussion.
That could be a possible outcome. Still, possibly not the ideal one... have you thought of other alternatives or are you just deciding that alone (I'm new here, but I don't think this works by "single person decisions")?
I'll just name a few:

  • Merging a page where we talk about both.
  • Having a page for prop (most used) and talk about attr there.

The thing here is: people want to manipulate properties/attributes of the DOM nodes; they are still a bit confused about the difference... what do you think is the ideal option?
INMHO, having two pages: one for attr and other for prop is almost cloning the official API docs. You don't want that here. Here, you want "how to's", didactic stuff where you teach the stuff in a "cookbook" form and not in a "function oriented" manner.

@rwaldron
Copy link
Member

simply closing before the discussion ends does not promotes discussion.

Your changes are incorrect, that's why I closed it.

Having a page for prop (most used) and reference the other.

That's the solution, but that's not this PR. The correct way to do this is to file an issue first, to have the discussion and come to an agreed solution.

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

ok :)

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

If that's the solution... why not use this page and transform it? Why have this page after all if you could simply tell the whole story in a "Properties" page?

@ajpiano
Copy link
Member

ajpiano commented Feb 18, 2013

@lsoares we can make that assessment once there is a "Properties" page to discuss :) - the need to read and set attributes is never going to just "go away" - I think there will still need to be a low-level page just explaining the concept of actually getting/setting attributes at all. I think @timmywil's presentation (http://timmywil.github.com/pres/attributes/#landing) is a good jumping off point for a more thorough didactic discussion

@rwaldron
Copy link
Member

@lsoares in case it's not clear, we'd like you to draft the "properties" page—but let's do it in a fresh PR. Also, are familiar with using git locally?

@lsoares
Copy link
Contributor Author

lsoares commented Feb 18, 2013

@ajpiano I never said attributes should disappear. I'm only arguing they should not have the spotlight they have.
Properties should have the spotlight with some notes on attributes. I'm still not convinced attributes deserve a page on their own (to me they only deserve some side notes on the Properties page)... but if I'm the only one saying that... I'll leave it behind..

Nope.. I'm not familiar with local Git but I'll try to be soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants