複数の div を持つ Web ページがあります。ユーザーが本文をクリックすると、すべての div 要素の境界線が赤に変わります。ただし、ユーザーが div をクリックすると、その div のみが境界線を青に変更します。他のすべての div 要素は赤い境界線のままになります。これはこれまでの私のコードです:
$('body').click(function() {
var $target = $(event.target);
if (!target.closest($('div')).length) {
//I want the border of all div on the page to change to red
$('div'). css('border', '2px solid red');
} else if (target.closest($('div')).length) {
//Here just the div that was clicked on will have its border changed to blue
$(this).css('border', '2px solid blue');
}
});