0

I just read jQuery 3.0's breaking changes, and I think this should be known by all front-end engineers.

e.g. Questions, 1. how to uncheck a checkbox? 2. how to remove checked from radio button?

$('input').prop('checked', false);
Yumiko
  • 448
  • 5
  • 16
  • 2
    I don't understand what the point of this question is. I'm inclined to close it as duplicate of [How to uncheck a radio button?](http://stackoverflow.com/q/2117538/218196). If this about a specific breaking change in jQuery 3, then you should explain what the change actually is and what your question about is. Simply repeating documentation from jQuery is not useful. Stack Overflow is not your blog or Twitter or . – Felix Kling Jun 12 '16 at 05:34
  • I think my question is what's the difference between removeAttr and prop. – Yumiko Jun 12 '16 at 05:36
  • `prop` allows you to set the values of DOM properties. `removeAttr` removes HTML attributes. Did you read the documentation? What is still unclear after you read it? And what is the breaking change? – Felix Kling Jun 12 '16 at 05:37
  • @FelixKling - the OP has asked and answered their own question as a PSA. – nnnnnn Jun 12 '16 at 05:44
  • @nnnnnn: I've seen that. I still don't see a reason for the question though (or it's poorly phrased for what it is trying to accomplish). – Felix Kling Jun 12 '16 at 05:45
  • Possible duplicate for http://stackoverflow.com/questions/6169826/propchecked-false-or-removeattrchecked – Vivek Pratap Singh Jun 12 '16 at 05:51
  • @FelixKling yes, that makes sense to me. The reason that I raised this question was because I thought some people may ask similar questions if they first learn jQuery. – Yumiko Jun 12 '16 at 05:53
  • I updated [.prop('checked',false) or .removeAttr('checked')](http://stackoverflow.com/q/6169826/218196) with the jQuery 3 information. I think this question should be closed as duplicate. – Felix Kling Jun 12 '16 at 06:08

1 Answers1

2

It is almost always a mistake to use .removeAttr( "checked" ) on a DOM element. The only time it might be useful is if the DOM is later going to be serialized back to an HTML string. In all other cases, .prop( "checked", false ) should be used instead.

https://jquery.com/upgrade-guide/3.0/#feature-new-signature-for-jquery-get-and-jquery-post

Yumiko
  • 448
  • 5
  • 16
  • 1
    This isn't new with jQuery 3: it was *always* the case that setting the `checked` property to `false` was better than removing the attribute. *"In all other cases, .prop( "checked", false ) should be used instead."* - I know you're quoting the jQuery people, but that's not correct either: you shouldn't say `$(this).prop("checked", false)` in cases when you can just say `this.checked = false;`. – nnnnnn Jun 12 '16 at 05:43