Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
function MyClass() {
    var id_nr = Math.ceil(Math.random() * 999999);
    this.button_id = 'button_' + id_nr;
}
MyClass.prototype = {
    createButton: function() {
        var msg = 'Button \'' + this.button_id + '\' was clicked';
        var my_button = $('<input>')
                .prop('type', 'button')
                .prop('id', this.button_id)
                .val('Click Me')
                .on('click', function () { alert(msg) } );
        $('body').append(my_button);
    }
};
window.onload = function() {
    var s = new MyClass();
    s.createButton();
  
    var w = new MyClass();
    w.createButton();
  
};
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
sunyatasattvapro
0viewers