$('.cut').each(function() { if ($(this).hasClass('cut-top')) $(this).css('border-right-width', $(this).parent().width() + "px"); else if ($(this).hasClass('cut-bottom')) $(this).css('border-left-width', $(this).parent().width() + "px"); });