The problem is that I do not know js well and can not figure out how to realize my idea. There is a form that after a successful bid creates a class of type itself - formsuccess. I want to hang the function on the submit button to call the function and check if the formsucces class appeared, if yes, then call the goal function. ga ('send', 'event', 'form', 'succes'); return true;

I do not understand how to call a function simply when searching for a class.

I can not find a similar situation and material how to properly create and call such a function. Well, it is desirable to make this launch a function at intervals so that the form has time to get status.

    1 answer 1

    I simplified one of my functions (if I understood the task correctly):

    function submitForm(){ $("form.form:not(.no-ajax)").submit(function(){ var form=$(this); $.ajax({ method:"post", url:form.attr("action")+"&ajax", data:form.serialize(), cache:false, error:function(){ //show some error }, success:function(result){ form.addClass("formsuccess"); ga('send', 'event', 'form', 'succes'); } }); return false; }); } 

    The point is that after successfully submitting the form, we do what we want next. Try this implementation. Or, in your case, call ga() immediately after adding the class to your form.

    • Yes, but how to call the function immediately after adding the class?) - Nikita Severin
    • In my example, the call for tracking an analytics goal goes right after adding a class, you can do the same - DaemonHK
    • Just great. I had to sort out this issue in more detail, I had not worked with Ajax before. As it turned out, there are no need for classes, I just give a goal if the result is ok. Thank! - Nikita Severin