简体   繁体   中英

Trigger only One element on click

I have this DOM:

 <article>
   <overlay>
     <IMG>
   </overlay>
   <div class="wrapper">
   </div>
 </article>

<article>
   <overlay>
     <IMG>
   </overlay>
   <div class="wrapper">
   </div>
 </article>

In jquery i need to create this function:

 $("IMG").on("click", function () 
 {$(".wrapper).CSS("display","block"})

But this function has to work only on the clicked element. Suggestions?

Try something like this:

$('img').on('click', function () {
  $(this).closest('article').find('.wrapper').css('display', 'block');
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM