javascript - jQuery: use var shortcut to assign data and how to chain function to run on load and click -


i've got two-part question.

one: can use last variable set update value on line after if (!last) {? i.e., last = size;?

    var j$ = jquery.noconflict();      function updatecount() {         var self = j$(this),             last = self.data('last'),             size = self.val().length,             span = j$('.currentcount');          if (!last) {             self.data('last', size);         } else if (last != size) {             span.text(size);             self.data('last', size);         }     }      j$('textarea[id$=textbody]').on('propertychange change click keyup input paste', updatecount); 

secondly, can chain .on('propertychange ... line have updatecount run script loaded?

question 1:

no, can not use assignment variable because there no data-binding in jquery. updating last variable never update data-last of jquery object.

question 2:

this used do:

j$('textarea[id$=textbody]').on('propertychange change ...', updatecount).change(); 

where change() automatically triggers function.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -