"... by class and div."
I assume that when you say "div", you mean "id"? Try the following:
$('#test2.test1').prop('checked', true);
No need to guess with the [attributename=value] style selectors, because id has its own format , like class , and they are easy to combine, although, given that the identifier must be unique, it should be sufficient for yourself, if only your the meaning is not "select this element only if it currently has the specified class."
Or, as a rule, to select the input where you want to specify several attribute selectors :
$('input:radio[class=test1][id=test2]').prop('checked', true);
That is, specify each attribute with its square brackets.
Note that if you do not have a fairly old version of jQuery, you should use .prop() rather than .attr() for this purpose.
nnnnnn Apr 11 '13 at 12:55
source share