DEV Community

Cover image for jQuery trigger()
Luca
Luca

Posted on

1

jQuery trigger()

Hi dev!πŸ™‹β€β™‚οΈ

During my work i used an event looks very interessant: is a trigger() event.

The trigger() method triggers the specified event more times:
πŸ§‘β€πŸ’»

<button type="button" class="click"> CLICK </button>

<div class="container">
</div>
Enter fullscreen mode Exit fullscreen mode
$('.button').click(function(){
    $(document).trigger('nameOfMyTriggerEvent')
})

$(document).on('nameOfMyTriggerEvent', function(){
    $('.container').hide();
})

Enter fullscreen mode Exit fullscreen mode

It's easy and very usefull if you need to trigger an event more times.

Hope it helpfully!
✌️

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay