How to add the checked = "checked" attribute to the output of a .html () method

There must be something special about the checked flag attribute, either at the jQuery level or at the DOM level. Using this HTML:

<html>
    <body>
        <input id="cb" type="checkbox" />
    </body>
</html>

And this javascript:

$(function() {

    $("#cb").attr("checked","checked");
    alert("Expecting this HTML fragment to have a 'checked' attribute:\n\n"
          + $("body").html());

});

I do not understand what I expect; if I use an attribute name other than "checked", it works as expected.

The reason I'm trying to get this to work is to get the HTML that exists in the DOM browser and convert it to PDF so that users can get PDF versions of the page as they are. looking at him; it was heavily manipulated on the client side, so getting the right HTML directly from the server is not an easy option.

Here's the working version of the code above: http://jsfiddle.net/pettys/qTfDP/2/

+3
1

jQuery 1.6. attr 1.6/1.6.1.

+4

All Articles