3

There must be something special about the checked attribute of a checkbox either at the jQuery level or the DOM level. With 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'm not getting what I expect; if I use an attribute name besides "checked" it works as expected.

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

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

0

1 Answer 1

4

Update to jQuery 1.6. There have been some significant changes to attr in 1.6/1.6.1.

Sign up to request clarification or add additional context in comments.

3 Comments

Makes sense. Thanks for the link, too - glad to know the background.
@pettys I think the underlying problem is that until 1.6 attr was setting the DOM property checked without adding the attribute in the markup.
I hadn't thought about the distinction between setting attributes and setting properties until I read the link you had sent. Good stuff!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.