user2000423
user2000423

Reputation: 101

How to append check box in jquery

How I add checkbox after span in below code.

var aaa = $('<a/>')
.html("<span>"  "</span >" + " <span>""</span> ")                       
.attr('data-transition', 'slide') 
.appendTo(li);

Upvotes: 0

Views: 313

Answers (3)

Alexander
Alexander

Reputation: 23537

You can also make use of the html option.

var $a = $("<a/>", {
  "data-transition": "slide",
  "html": $("<input>", {
    "type": "checkbox"
  })
})
.appendTo(li);

It will render this HTML:

<a data-transition="slide"><input type="checkbox"></a>

Upvotes: 0

Jai
Jai

Reputation: 74738

Your .html() has several issues with concatenation:

.html("<span>"  "</span >" + " <span>""</span> ")    
     //------^^^^--------------------^^--------useless quotes are here.

this way:

.html("<span></span ><input type='checkbox' value='' />" + " <span>""</span> ") 

this way:

 .html("<span></span >" + " <span></span><input type='checkbox' value='' />") 

or after both:

.html("<span></span> <input type='checkbox' value='' />" + " <span></span><input type='checkbox' value='' />") 

Upvotes: 1

bipen
bipen

Reputation: 36551

just add the html tag for checkbox inside <span> try this

 .html("<span> <input type='checkbox' value='value' />test<input type='checkbox' value='value1' />test1</span >") ;         

Upvotes: 0

Related Questions