tags:

views:

20

answers:

1

Can we Make a checkboxList using jquery like we fill the options in select tag of html?

I am confused how to make a checkboxlist using Jquery in Html?

I have seen Method for creating option tag in select tag of HTML But I dont know how to create a checkbox list?

  $.fn.fillSelect = function(data) {
     return this.clearSelect().each(function() {
        if (this.tagName == 'SELECT') {
        var dropdownList = this;
        $.each(data, function(index, optionData) {
            var option = new Option(optionData.Text, optionData.Value);                
            if ($.browser.msie) {
                dropdownList.add(option);
            }
            else {
                dropdownList.add(option, null);
            }
        });
    }
  });
 }

any link of article that contains little bit this type?

A: 

Not sure what data represents, but this is basically what you need to do. You can create a new DOM element inline just by defining it within a call to jQuery via $().

$.fn.fillSelect = function(data) {
  var $select = $('select');

  for ( ... ) {
    var option = $('<li></li>').attr('value', optionData.value).text(optionData.text);
    $select.append(option);
  }
};
Matt Huggins
var $select = $('select'); is select is Id of element
SAHIL SINGLA
No, that will select all elements with a tag name of `select`.
Matt Huggins