简体   繁体   中英

Convert vanilla js to jquery

I have a problem in converting my websites vanilla js to jQuery
I want to convert

const blue = $('#color-blue'),
       red = $('#color-red');

blue.addEventListener('click', () => {
    delete chat.dataset.color;
});
red.addEventListener('click', () => {
    chat.dataset.color = 'red';
});

to use with jquery

While it is unnecessary to change the event listeners to jQuery, if for some reason you still want this, the below should work for you!

const blue = $('#color-blue'),
    red = $('#color-red');

blue.on('click', () => delete chat.dataset.color);
red.on('click', () => chat.dataset.color = 'red');

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