Home > Enterprise >  jQuery .click working in browser but not in game fivem
jQuery .click working in browser but not in game fivem

Time:02-22

i have a code that adds a onclick event to a button in jQuery and it works fine in chrome when i test it but when i test it in game it dosent even trigger the event

also im using defer attr in script tag to make sure event applies to button

$('.dv').click((e) => {
    fetch('https://vehiclemenu/vehiclemenu:triggerButtonEvent', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=UTF-8',
        },
        body: JSON.stringify({
            event: 'vehiclemenu:dv',
            id: e.currentTarget.classList[2]
        })
    });
});

EDIT: thanks to Ryano it works now the problem was if there is no .dv element you cant add .click event for it. its kinda stupid because it worked fine in browser

CodePudding user response:

Are there any .dv class elements at the time when this code is run? Perhaps try

$(document).on("click", ".dv", function(e){ ... }));
  • Related