I have a JavaScript variable that is in a jQuery wrapper.
var script1 = $("<label><input type='checkbox' value='script_"
+ scripts[i].id + "' id='pre_script_" + scripts[i].id
+ "'> " + scripts[i].name + "</label>);
I want to apply an attribute to the input tag. If I try simply
script1.attr('checked', true);
then the <label>
tag gets the attribute. I also tried
$(script1 + " input").attr('checked', true);
but this doesn't work. Is there a way to apply this attribute to the input tag instead?
答案 0 :(得分:2)
script1.find("input").attr('checked', true);