I have the following problem. I was forced to rewrite all of the following functions to create this:
$(document).on("change","#type_of",function(){
instead of this:
$('#type_of').on('change', function () {
I did this because I manipulate the DOM and after loading the contents through ajax all the functions stopped working. Now they work halfway because triggers don't do the job. All of the codes below are added to the index.php page. On this page, I have a div #content and I reload its contents via ajax. All of the following functions apply only to the div. My question is: how to create the right triggers for these functions?
One more question: is this the correct syntax in my case $(document).ready(function() { ?
$(document).ready(function() { // ALSO SOME CODE HERE (variables and etc.) $(document).on("change","#type_of",function(){ // FUNCTION CODE }) $(document).on("change","#order_form",function(){ // FUNCTION CODE }) $( '#type_of, #orer_form' ).trigger( 'change' ); }) $(document).on("change","input[name=window-type]",function(){ // FUNCTION CODE } $(document).on("change","#shutter_type",function(){ // FUNCTION CODE }) $( '#shutter_type, #input[name=window-type]' ).trigger( 'change' );
Here is also one of my ajax calls that I use to reload the contents of a div #content
function displayPhoto(photoid){ $.ajax({ url: "includes/displayphoto.php?photo_id="+photoid }).done(function(data) { if (data == false) { alert ("ERROR"); } else { $('#content').html(data); } }); } $(document).on("click",".photo-id",function(){ var photoid = $(this).data("photoid"); displayPhoto(photoid); });
source share