I'm using your fine little piece of code in a Bootstrap 3 modal pop up. I'm setting the value of the control, and it appears to get set correctly.
$("#rating").val(3);
alert($("#rating").val()); // 3
However, no stars are selected when the controls is rendered.
Tested in Chrome, FF, and IE.