3
$(document).ready(function() {
    var dataString="hy";
    var htmlnew="<input type='checkbox' name='formDoor' value='A' class='list' enable='true'>Check 1";

    alert(htmlnew);

    $(".list").change(function()
    {
        $("#regTitle").append(htmlnew);
    });
 });

The above is which i used when each time i check the checkbox with class list. i get a new one in #regTitle div, but the problem i am facing is the newly generated check boxes are not able to checked,can you guys tell me whats the problem?

2 Answers 2

1

You should delegate event handling with on() so that everything works also on newly added elements (jQuery > 1.7);

$("body").on("change", ".list", function()
{
$("#regTitle").append(htmlnew);
 });

if you use an older version of jQuery use delegate or live

$(document).delegate(".list","change", function()
{
$("#regTitle").append(htmlnew);
 });

$(".list").live("change", function()
{
    $("#regTitle").append(htmlnew);
});
Sign up to request clarification or add additional context in comments.

8 Comments

it saying $("body").on is not a function
@AlexMathew then you have an older version of jQuery, use live or delegate()
but still nothing change, look the .delegate and .on is not working but live work
@AlexMathew that's strange because live is a shorthand version of delegate(), anyhow if it works, ok
but nicola, still i dont get the output as i desire, what i mean by live got worked is, its not shown any error
|
0

Your checkbox's change event does not attach to the dynamically generated elements. You will have to delegate the bind. Using .on() is very good for this purpose.

$("body").on("change", ".list",function() {
    $("#regTitle").append(htmlnew);
});

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.