Reddy
Reddy

Reputation: 1497

KendoUI - Not working for Dynamically added Elements

$(document).ready(function() {
  $("select").kendoDropDownList();

});

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
});
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.3.1111/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.3.1111/styles/kendo.material.min.css" />

<script src="//kendo.cdn.telerik.com/2015.3.1111/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2015.3.1111/js/kendo.all.min.js"></script>


<div id="container">
  <select>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
  </select>
</div>

<a href="#" id="new">Add More</a>

I am new to jQuery and KendoUI

If I am using KendoUI code directly to elements, it is working. But If I create the element dynamically and try to apply, it is not working...

Please Help!

ONLINE DEMO

HTML

<div id="container">
  <select>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
  </select>
</div>

<a href="#" id="new">Add More</a>

SCRIPT

$(document).ready(function() {
  $("select").kendoDropDownList();

});

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
});

Upvotes: 0

Views: 997

Answers (1)

DinoMyte
DinoMyte

Reputation: 8858

Once you create the elements dynamically, you need to bind the kendoDropDownList again to the select tag.

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
  $("select").kendoDropDownList();
});

http://jsfiddle.net/avz15vsr/3/

Upvotes: 2

Related Questions