user1524462
user1524462

Reputation: 67

Strange behaviour jquery

I've seen this in some topics but haven't fixed my script.

I have a piece of jQuery that doesn't work because of I use it to manage (validate ) a piece of html (form ) that is loaded using a jQuery function load() after loading the page.

But if I put for example an alert("Something") in the script outside the functions, it works.

I've tried putting the validation script inside these beginnings but it doesn't work...

$(window).bind("load", function() {
$(document).ready(function () {

it is very strange... do have you a solution?

Update: working now, check the first answer's solution!

Upvotes: 0

Views: 72

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

From what I understand, you are trying to attach an event to an AJAX-loaded form, and it's not working because you're actually attaching it before the form exists.

Presumably you have .load(url) somewhere in there, so you should do this:

$("selector").load(url,"",function() {
    // do stuff to the loaded content, such as attaching events, here
});

Upvotes: 1

Related Questions