How to create a field similar to stackoverflow, click to reject

Duplicate: qaru.site/questions/56142 / ...


I am trying to create an error message that is displayed, there is still a rough attempt, the message is displayed normally, however the click does not work.

function message(somemessage){
       $(document).ready(function(){
            $('<div class="error">' + somemessage+ '</div>')
           .insertAfter( $('#ErrorMessage') ).fadeIn('slow').animate({opacity: 1.0}, 5000).click(function(){$(this).remove});
   });
 }
+3
source share
2 answers

Is it because you forgot to add parentheses after the function remove?

try it

$('<div class="error">' + "somemessage"+ '</div>')
           .insertAfter( $('#ErrorMessage') ).fadeIn('slow').
animate({opacity: 1.0}, 5000).click(function(){$(this).remove()});
+4
source

I have already answered how to do this in this matter .

If you want, just skip directly to the example.

However, if you want something more reliable, you have to check many solutions:

, , - (, , ..), , .

+10

Source: https://habr.com/ru/post/1708288/


All Articles