I have an event listener for a click on a specific div
.
$('div').on('click', function() {
var styles = $(this).attr('style').split(';');
$.each(styles, function(i) {
var style = this.split(':');
alert(style[0]);
if(style[0] == 'font-size'){
$('#controls #font-size option[value="'+style[1]+'"]').attr('selected', true);
} else if(style[0] == 'color'){
$('#controls #color option[value="'+style[1]+'"]').attr('selected', true);
} else if(style[0] == 'text-align'){
$('#controls #text-align option[value="'+style[1]+'"]').attr('selected', true);
}
});
});
The alert()
will display the style property (e.g. font-size, color, width), but the if
statement is not functioning as expected.
Any advice on how to fix this?