javascript - Jquery Not Synchronized with the DOM -


i found new problem when manipulate dom using jquery. dom not updated.

here go.

var postcard = function($root) {     this.$root = $root;     this.stuff_id = this.$root.data('stuff_id');     this.id = this.$root.data('id');     this.is_owner = this.$root.data('is_owner');     this.$propose_button = null;     this.$favorite_button = null;     this.init();     this.initevents(); };  postcard.prototype.init = function () {         this.$propose_button = this.$root.find("." + postcard.prototype.css_classes.propose_button); this.$proposal_box_modal = this.$root.find("." + postcard.prototype.css_classes.proposal_modal); this.$proposal_box = this.$root.find("." + postcard.prototype.css_classes.proposal_box); this.$favorite_button = this.$root.find(".post-card-button-favorite"); this.$total_favorite = this.$root.find('.post-card-total-favorite'); this.$image_view_editor = this.$root.find("#" + this.id + "-image-view"); this.image_view_editor = new imagevieweditor(this.$image_view_editor); this.proposal_box = new homeproposalbox(this.$proposal_box);  };  postcard.prototype.initevents = function() {     var self =this;     $(document).on("click", "#" + this.id,function(e) {          if(e.target && $(e.target).hasclass('post-card-button-propose') ){             if(self.is_owner ) {             return false;             }                if(commonlibrary.isguest()) {                 return false;             }             self.$proposal_box_modal.modal("show").load($(this).attr("value"));         } else if(e.target && $(e.target).hasclass('post-card-button-favorite')) {             self.clickfavoritebutton_();         }     });   postcard.prototype.clickfavoritebutton_ = function() {         this.markfavorite(); };  postcard.prototype.markfavorite = function() {      this.$favorite_button.addclass('post-card-button-red');   }; 

when favorite button clicked, clickfavoritebutton() trigerred, , markfavorite method fired next. problem although this.$favorite_button updated (the class added variable), dom in page not updated happens dynamically loaded element, , not happen element has been around since page loaded.

the postcard created in postlist class

/*   * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */   var postlist = function($root) {     this.$root = $root;     this.stuff_ids = '';     this.id = $root.data('id');     this.location = $root.data('location');     this.query = '';     this.post_cards = [];     this.$post_list_area = null;     this.permit_retrieve_post = true;     this.init();     this.initevents(); };   postlist.prototype.scroll_value = 95;  postlist.prototype.init = function() {     $.each($(".post-card"), function(index, value) {         this.post_cards.push(new postcard($(value)));          if(this.stuff_ids === '' ) {             this.stuff_ids += $(value).data('stuff_id');         } else {             this.stuff_ids += "," + $(value).data('stuff_id');            }     }.bind(this));      this.$post_list_area = this.$root.find('.post-list-area'); };  postlist.prototype.initevents = function() {     $(window).scroll({self:this}, this.retrievepostwhenscroll_); };  postlist.prototype.retrievepostwhenscroll_ = function(e) {     var self = e.data.self;     var scrollpercentage =              ((document.documentelement.scrolltop + document.body.scrolltop) /              (document.documentelement.scrollheight - document.documentelement.clientheight) * 100);     if(scrollpercentage > postlist.prototype.scroll_value) {         if(self.permit_retrieve_post) {             self.permit_retrieve_post = false;             $.ajax({                 url: $("#base-url").val() + "/site/get-more-posts",                 type: 'post',                 data: {'ids' : self.stuff_ids, query: self.query, location: self.location},                 success: function(data) {                     var parseddata = json.parse(data);                     if(parseddata['status'] === 1) {                         self.$post_list_area.append(parseddata['view']);                         $(parseddata['view']).filter('.post-card').each(function(index, value) {                             self.post_cards.push(new postcard($(value)));                             self.stuff_ids += "," + $(value).data('stuff_id');                         });                     }                     self.permit_retrieve_post = true;                 },                 error : function(data) {                     self.permit_retrieve_post = true;                  }             });            }     }  }; 

when scroll page, retrievewhenscroll method fired , postcard dynamically added


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -