I use event.target but if when i do bold for selected element with toggleClass. When i was click other elements they are all change. But my mousedown event is didnt just interest with single target ?
function tik(xs){
$.each(['bold', 'italic', 'right', 'left', 'center'], function(index, elem) {
var x = xs; // e.target or drag event for this variable becomes to ui.helper
if($(x).is('.drag') || $(x).is('.drags') ){
if($(x).hasClass(elem))
$(`.fa-${elem}`).addClass('selected');
else
$(`.fa-${elem}`).removeClass('selected');
if(index <= 1 ) { // bold and italic is 0-1 , left,r... 2-3-4
$(`.fa-${elem}`).click(function() {
$(x).toggleClass(`${elem}`);
$(`.fa-${elem}`).toggleClass('selected');
});
} else {
$(`.fa-align-${elem}`).click(function() {
$(x).toggleClass(`${elem}`);
$(`.fa-align-${elem}`).toggleClass('selected');
});
}
}
// $(x).addClass('parlak') // kontrol gelmeli
});
}
How i find cause to this problem ? I tried a lot but i dont find. If a connect that with drag event, good works but this time not to be realtime and need do it dragging for seen
I captured a video for show you
I know here is code all suck like sphagetti. But i coulndt do it. I was try lot of thing. Much more thing changed when i was working
Here is have a simplification status
$(document).mousedown(function(e,i) {
// tik(e)
var lastClicked;
if($(e.target).is('.drag') || $(e.target).is('.drags') ){
lastClicked = e.target;
}
$('.fa-bold').click(function(){
$(lastClicked).toggleClass('bold');
})
});