Skip to content
Advertisement

Material Design Lite Switch not working on jquery load

I am trying to load MDL Switch through external file but it’s not working.

Here is my main page code : index.php

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="material.min.css">
</head>

<body>
<a href="#" class="lo">Load</a>
<div class="demo-switch">

<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-2">
<input type="checkbox" id="switch-2" class="mdl-switch__input" />
<span class="mdl-switch__label">Bluetooth</span>
</label>

</div>

<script src="js/material.min.js"></script>
<script src="js/jquery.js"></script>
<script>
$(document).ready(function(){

  $.getScript("js/material.min.js").done(function(){

      $(document).on("click",".lo",function(){
      $('.demo-switch').load("new_test.php");
      });
  });



});

</script>

</body>
</html>

Here is file new_test.php

<div class="demo-switch">

<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-2">
<input type="checkbox" id="switch-2" class="mdl-switch__input" />
<span class="mdl-switch__label">Bluetooth</span>
</label>

</div>

Here are the result after i press load button:

Here are the result after i press load button

possible js is not working properly but i can’t find a way to fix this. please help

Advertisement

Answer

You Will need to call componentHandler.upgradeAllRegistered() for dynamic dom.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement