0

I am building a html page using dom concept, but the checkbox is not displaying in the html page. My code is below.

if (condition <= 0) {
 $doc = $(document.createElement("li")).attr({
     id: id,
     name: name,
     'class': 'liBullet'
 })
}

else {
 $doc = $(document.createElement("ul")).attr({
     id: id,
     name: name,
     'class': 'liBullet'
 })
}

$doc.append(
    $(document.createElement("input")).attr({
     id: id,
     type: "checkbox",
     name: name,
     'class': 'layerCheck'
    })

    .append(
        $(document.createElement("label")).attr({
          id: id,
          name: name
        })
    ).text(name)

    .append(
        $(document.createElement("div")).attr({
         id: id,
         'class': 'loadingLegend'
        })
    )).appendTo("#layer_list");
}
2
  • I hope you are not using Javascript to build out your entire html page. You could must more easily just write <input type="checkbox" name="blah" class="layerCheck" /> Commented Dec 12, 2012 at 14:41
  • but my client need to asj this type only thats y Commented Dec 12, 2012 at 14:50

2 Answers 2

3
$(document.createElement("input")).attr({
                                     id: layer.id,
                                     type: "checkbox",
                                     name: layer.name, // <---- missing comma?
                                     'class': 'layerCheck'
                                 }); // <-- or missing semicolon?

Also, you don't need to use createElement, you can just do:

$("<input />").attr({
                       id: layer.id,
                     type: "checkbox",
                     name: layer.name,
                  'class': 'layerCheck'
              }).appendTo("body");
Sign up to request clarification or add additional context in comments.

2 Comments

thats the not problem i need to append the some pther data so i didnot use the ; any other idea?
@user279 Then post the whole statement! How can he evaluate your syntax if you are only giving him part of the statement?!?!?
0

you can also use this :

$("<input type='checkbox' id='id' name='name' value='val'/>").appendTo("body");

or

$("body").append("<input type='checkbox' id='id' name='name' value='val'/>");

read about append & appendTo

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.