This is purely for me and to remind myself of the frequently used jQuery expressions. Forgetfulness is a curse as well as a bliss!
- Make the first option of <select > selected (http://stackoverflow.com/questions/1414276/how-to-make-first-option-of-select-selected-with-jquery)
$("#target option:first").attr('selected','selected');
- populate select list dynamically. This simply replace html. If there is a better way, please let me know. I used an extension method, Html.ClientIdFor.
function(result) {
var options = '';
for(var i=0; i<result.length; i++) {
options += '<option value="' + result[i].Id + '">' + result[i].Name + '</option>';
}
$('#<%= Html.ClientIdFor(m => m.Input.ProductCategoryId) %>').find('option').remove().end().html(options);
$('#<%= Html.ClientIdFor(m => m.Input.ProductCategoryId) %> option:first').attr('selected', 'selected');
}
- table and click on a link on table row
$('#result').delegate('a[name="lnkDescription"]', 'click', function(e) {
e.preventDefault();
var link = $(this).closest('tr').find('a[name="lnkDescription"]');
...
});
})