Created a new input element and tried adding the data attribute using the data method in jquery but am not able to append the value
var txtBox = $('<input/>', {
"class": "myCustomClass",
"type": "text"
});
$('#wrapper').append(txtBox);
txtBox.data('index', '1');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='wrapper'>Input Text Box : </div>