On 1/18/11, Diego Perini <[email protected]> wrote:
> On Tue, Jan 18, 2011 at 7:15 PM, Miller Medeiros
> <[email protected]> wrote:
>>
>> On Tue, Jan 18, 2011 at 9:47 AM, Diego Perini <[email protected]>
>> wrote:

[...]
>
> My intervention was meant as a big warning against the (probably
> unwanted) side effects produced by those specific methods and the
> confusion they could create in future readers or in people trying to
> learn HTML, DOM and Javascript.
>
Yes, the side effects from removeAttr are the worst -- Errors! That's
another can 'o worms.

And so there is a library - jQuery which does not do what its
documentation states, and throws errors. But look how jQuery has
affected FE Eng. This is the state of the art:

http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_disable.2Fenable_a_form_element.3F
"How do I disable/enable a form element? "
| There are two ways to disable/enable form elements.
|
| Set the 'disabled' attribute to true or false:
No, setting the attribute is not the way to do it.

Setting the attribute would be doing this:
inp.setAttribute("disabled", true);

In compliant browsers, that won't cause the element to become disabled.

| // Disable #x
| $('#x').attr('disabled', true);
|  // Enable #x
|  $('#x').attr('disabled', false);
|
| Add or remove the 'disabled' attribute:

No, attributes is totally wrong here. Adding, removing won't have any
side effects. And adding and removing are not what "attr" and
"removeAttr" do anyway -- those functions read and modify properties,
with side effects.

|  // Disable #x
|  $("#x").attr('disabled', 'disabled');
|  // Enable #x
|  $("#x").removeAttr('disabled');


Here is another question from their FAQ:
http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_check.2Funcheck_a_checkbox_input_or_radio_button.3F
| How do I check/uncheck a checkbox input or radio button?
|
| There are two ways to check/uncheck a checkbox/radio button.
|
| Set the 'checked' attribute to true or false.
|

No, that is wrong and it is confusing people.

|  // Check #x
|  $('#x').attr('checked', true);
|  // Uncheck #x
|  $('#x').attr('checked', false);
|
| Add or remove the 'checked' attribute:
|
No, dammit! Reading attributes is not what attr does.

|  // Check #x
|  $("#x").attr('checked', 'checked');
|  // Uncheck #x
|  $("#x").removeAttr('checked');

That might work in jQuery, but it is *not* as the standards dictate.
<sarcasm>
And here is the state of the art in front end engineering:
http://stackoverflow.com/questions/4012649/removeattrselected-showing-error-in-ie6
http://stackoverflow.com/questions/1456790/jquery-removeattribute-error-in-ff
</sarcasm>

<hifive/>
-- 
Garrett

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to