0

I have this 'template' code (just for example):

$(document).on("<EVENT>", "form", function() {
    $(this).find(".input input").each(function() {
        var required = $(this).attr("required");
        var checkField = $(this).closest("tr").children(".check");
        var errorField = $(this).closest("tr").children(".errormessage");
        if (required != undefined) {
            $(checkField).css("color", "#FFFF00");
            $(checkField).html("&#x2718;");
            $(errorField).css("color", "#FFFF00");
            $(errorField).html("(Required)");
        }
        else {
            $(checkField).css("color", "#FFFF00");
            $(checkField).html("&#x2714;");
            $(errorField).css("color", "#000000");
            $(errorField).html("");
        }
    });
});

When <EVENT> is for example click or mouseover, it just works as expected.
However it refuses to work on an ready or load event, any clue why?

6
  • There is no ready or load event for a form. The form is ready, when the document is ready. Have a read of the .ready docs for jQuery. Dec 5, 2013 at 13:15
  • the $(document).on(...) is itself called on page load and im not sure why you want to trigger it automatically, if you want to execute some js code on page load then enclose those inside $(document).on(...)` Dec 5, 2013 at 13:15
  • ready or load is just for the document, what you expect by form load?
    – Andrew
    Dec 5, 2013 at 13:15
  • wat are you doin and why dont you write your mark up directly rather than complicating it unnecessarily.. Dec 5, 2013 at 13:16
  • I am trying to preprocess a form when it is being "loaded"/"rendered", independent of whether it is directly loaded or comes in via HTML code out of an AJAX call.
    – skiwi
    Dec 5, 2013 at 13:18

1 Answer 1

1

From http://api.jquery.com/on/

In all browsers, the load, scroll, and error events (e.g., on an element) do not bubble. In Internet Explorer 8 and lower, the paste and reset events do not bubble. Such events are not supported for use with delegation, but they can be used when the event handler is directly attached to the element generating the event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.