Monday, March 10, 2014

How to create the button dynamically using jquery and add click event for that button and display alert message?

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Test Page</title>

</head>
<body>
<div>
<p>CSS3 allows you to format your elements using 3D transforms.

In this chapter you will learn about some of the 3D transform methods:

rotateX()
rotateY()
Click on the elements below, to see the difference between a 2D transform and a 3D transform:</p>
</div>
<script>
$(document).ready(function(){
$('<input type="button" width="80px" height="30px"/>').on('click',function(){alert('clicked')}).appendTo('div');

/* or
   $('<button />').on('click',function(){alert('clicked')}).text('click me').appendTo('div');  */
});
</script>

</body>
</html>

No comments:

Post a Comment