jQuery set a radio input

I finally found the answer here:
https://stackoverflow.com/questions/9525128/jquery-set-radio-button
https://web.archive.org/web/20160421163524/http://vijayt.com/Post/Set-RadioButton-value-using-jQuery

Basically, if you want to check one radio button, you MUST pass the value as an array:

$('input:radio[name=cols]').val(['4']);
$('input:radio[name=rows]').val(['3']);

So no more of these pre/post v1.6 versions:

$("#radio_1").prop("checked", true);
$("#radio_1").attr('checked', 'checked');
$("input[name=background][value='some value']").prop("checked",true);
$("#radio_1").prop("checked", true).change();
$(this).attr({"checked":true}).prop({"checked":true});
$("[name='type']").click(function(){
  $("[name='type']").removeAttr("checked");
  $(this).attr({"checked":true}).prop({"checked":true});
});
// JQueryUI
$("#option2").prop("checked", true); // Check id option2
$("input[name='radio_options']").button("refresh"); // Refresh button set

Have a nice day!

Loading speed vs code readability

ctrl-ZVXAs a developer I like structured code. The browser however could not care less about the right amount of tabs and spacing; it just need to get the code, with as little data-traffic as possible.

So, what do I do? When speed is really important, I create my stylesheets and javascripts as I normally do, but then also convert these into a “.min’ version – minified, and refer to those from the html source code.

To get this done Continue reading Loading speed vs code readability