JSFiddle - React, Tailwind, and code Playground
by jyrkim
HTML
<div id="blocs-container"> test
</div>
<div class="block" data-id="blocks"> test block
</div>
JavaScript
function Bloc() {
// initialize with value 2 for testing purposes
var startPosX = 2;
this.DOMel;
this.ID = Math.round( Math.random() * 1000);
this.init = function() {
$('#blocs-container').append( '<div class="bloc" data-id="' + this.ID + '"></div>' );
this.DOMel = $('.bloc[data-id="blocks"]');
// the code below didn't work
//this.DOMel.bind('touchstart', function(e) {
// so I used jQuery selector like below
$('.block[data-id="blocks"]').bind('touchstart', function(e) {
console.log("startPosX before " + startPosX);
startPosX = e.originalEvent.touches[0].pageX;
console.log("startPosX after " + startPosX);
});
}
}
var b = new Bloc();
b.init();
//console.log(b.startPosX());