3

I have the fallowing HTML:

<input type="checkbox" id="checkbox-remember" data-theme="SingleLineCheckBox" checked/>

but the checkbox still is not defaultly checked. I also tried using:

$("#checkbox-remember").prop('checked', true);

But i cant get it to work?

5
  • jsfiddle.net/aNrpL your checkbox is checked by default, your HTML is fine. Did you uncheck it at some stage and press refresh? Certain browsers remember your form settings even if you refresh. Close the tab, clear cache, and try again. Commented Dec 17, 2013 at 7:47
  • Thanks. I did all that. but it is still not checked when i first open the page. maybe it's something to do with jQuery? Commented Dec 17, 2013 at 7:49
  • What browser are you using? Perhaps the checked attribute is causing issues in earlier versions of IE? Commented Dec 17, 2013 at 7:50
  • both are working here : jsfiddle.net/techunter/x9dc7 which browser are you using? third one using checked="checked" Commented Dec 17, 2013 at 7:52
  • I am using chrome, and the file is a JSP file. when i view the source of the page, it seems like the "checked" attribute has vanished from the html... Commented Dec 17, 2013 at 8:00

4 Answers 4

3

Make always sure that your DOM is ready!

$(function(){  // DOM ready shorthand

    $("#checkbox-remember").prop('checked', true);

    // other code here

});

otherwise if you're able to change your HTML you can add the checked property to your checkbox. i.e: <input type="checkbox" checked="checked" />

It's also a good habit to put all you <script> tags right before the </body> tag making sure that the parser first read all your document tree before loading scripts.

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

1 Comment

Good find, I always just assume people wrap their jQuery in doc ready.
2

Try this one:

<input type="checkbox" id="checkbox-remember" data-theme="SingleLineCheckBox" checked="checked"/>

2 Comments

yup, checked="checked" will help IE
@user2951938 you have not give the name to that checkbox try by giving the name attribute also.
0

Try this

<input type="checkbox" checked="checked" id="checkbox-remember" data-theme="SingleLineCheckBox" />

Comments

0

have you got try other methods to know if the checkbox is check ?

I Have tried with

$('#checkbox-remember').get(0).checked

Demo

Comments

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.