Instead of removing CSS styles, why not just add it to the clicked object?
Get the identifier of the object with a click and use it ...
$(document).on('click', '.listElement', function () { var clickEl = this.id; //ID of clicked object $('.listElement').not('#' + clickEl).css('font-weight', 'bold'); //bolds everything which is NOT the clicked item. alert(this.id); });
or
$(document).on('click', '.listElement', function () { $('.listElement').not('#' + this.id).css('font-weight', 'bold');
Updated script
if there is a specific reason, you need to remove the style, not apply it ...
$(document).on('click', '.listElement', function () { $('.listElement').css('font-weight', 'bold'); alert(this.id); $('.listElement#' + this.id).css('font-weight', 'normal'); });
Script for
Scott source share