Home > OS >  Using Jquery to fade out any element which is clicked on
Using Jquery to fade out any element which is clicked on

Time:10-03

Im still very new to jQuery and im not sure why this is not working. I want to fade out any element which is clicked on using using jQuery.

html:

<head>
  
  <script src="https://code.jquery.com/jquery-3.6.0.js"></script>

  <script src="basicFile.js" defer></script>
  <title>fade Out any clicked on element</title>
</head>
<body>
  <p>
    Lorem ipsum dolor, sit amet consectetur adipisicing elit. Sed magnam nisi animi itaque labore tempore porro iure
    amet accusamus? Eos, similique! Maxime maiores totam rem!
  </p>
  <div>enter code here
    this is another paragraph
  </div>
</body>

Script:

$(document).ready(
  $('*').on('click',
    () => $(this).fadeOut(2500)
  )
)

I have also tried:

$(document).ready(
  $('*').click(
    () => $(this).fadeOut(2500)
  )
)

CodePudding user response:

I guess you need something like this:

$(document).ready(function() {
    $(this).click(function(event) {
         $(event.target.id).fadeOut(2500);
    });
});

CodePudding user response:

$(document).on('click','#elementID', function (){
               $(this).fadeOut();})
  • Related