1

I have a function where you click on something and then a resizable div toggles with content loaded (.load function).

$("#menucontent").load("loader.php?c=menup");
$("#menucontent").draggable();
$("#menuc").click(function(){
$("#menucontent").toggle(); //
$("#menucontent").resizable();
});

Basically this loads the data from loader.php to the div with id menuc. So far so good.. Data retrieved from loader.php :

echo '<a class="offertezoek" href="#">ZOEK OFFERTE<div style="display:none;" id="offertezoek"><input type="text" id="offertezoek" name="offertezoek">TEST</div></a><br /><br />';

Now the problem comes, I want to create a function for the data loaded. The data gets loaded but the function does not work.

Is this because the page is already ready and Jquery executed all the javascript before the data was in the div offertezoek (got added afterwards with .load("loader.php") ??

NEW FUNCTION :

$(".offertezoek").click(function(){
$("#offertezoek").toggle(); //
});
2
  • You can pass a callback to the load function. If a callback is provided, it is executed after post-processing and HTML insertion has been performed. See api.jquery.com/load Commented Jul 9, 2013 at 17:53
  • Thanks I think this also should work. Commented Jul 9, 2013 at 18:10

1 Answer 1

2

Try this

$(document).on('click', '.offertezoek', function(){
   $("#offertezoek").toggle(); //
});
Sign up to request clarification or add additional context in comments.

9 Comments

.live() may work better in case of jquery dynamically loaded content.
Thanks, this works great ! Can you explain me why ? Was I thinking in the right direction ?
@Mikhail, live() is deprecated since 1.7
Thanks, Mikhail. How do you mean .live instead of .on ? What is the difference. I thought .on function was only for old Jquery versions.
@dr3 The opposite- on() is new, .live() is deprecated and shouldn't be used anymore. For why this works, see the jquery api documenation for .on
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.