it seems simple enough, I donโt know if this is a mistake or just something I am doing wrong.
What I want to do is create a checkbox in jquery and then return the input line. I have this code:
var obj = $('<input>'); obj.attr('disabled', 'disabled'); obj.attr('type', 'checkbox'); obj.attr('checked', 'checked');
no matter how i try to execute this obj, the attribute 'checked' is never output.
So I tried:
$('<div>').append(obj).remove().html();
and it returns:
<input type="checkbox" disabled="disabled" />
I tried to set the id attribute, it does not matter. I also tried this, but it does not work:
obj.attr('checked', true);
Any suggestions on how to get an input tag processed using a verified attribute set to "checked" (via jquery)?
I understand that I can just do this by concatenating strings, but now I really want to know why it doesn't work as it should.
EDIT
You can try this for yourself in firebug. Create an obj object both my way and cletus , then try making it a string. You will find that the "checked" attribute will never be displayed.
jquery checkbox
benpage
source share