Add toggle button via Javascript
Description
The following code shows how to add toggle button via Javascript.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.6.4.js'></script>
<link rel="stylesheet" type="text/css"
href="http://jquerymobile.com/demos/1.2.0/css/themes/default/jquery.mobile-1.2.0.css">
<script type='text/javascript'
src="http://jquerymobile.com/demos/1.2.0/js/jquery.mobile-1.2.0.js"></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w ww .j a va2 s . com-->
$('button').click( function() {
var element = $ ('#test');
var toggle_button = '<select data-role="slider"><option value="off">Off</option><option value="on">On</option></select>';
element.append(toggle_button);
$('select').slider();
});
});
</script>
</head>
<body>
<div id='test'>
<button onclick="myFunction()">Add toggle button</button>
</div>
</body>
</html>