how to highlight a div for a few seconds using jQuery

前端 未结 5 2204
無奈伤痛
無奈伤痛 2021-02-08 01:04

I want to be add the following to a a page:

When a div is clicked, I want to:

  1. change the background color of the clicked on div for a few seconds
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 01:39

    One way is to go about like this using setTimeout:

    $(function () {
        $('div.highlightable').click(function () {
            $(this).addClass('highlighted');
            setTimeout(function () {
                $('div.highlightable').removeClass('highlighted');
            }, 2000);
        });
    });
    

提交回复
热议问题