jQuery auto numbering


/ Published in: jQuery
Save to your folder(s)

This plugin created in order to prepend() numbering to each matched element


Copy this code and paste it in your HTML
  1. jQuery.fn.autoNumbering = function(options) {
  2. var defaults = {
  3. inverted: false,
  4. delimiter: ". "
  5. }
  6.  
  7. var itemsLength = this.length;
  8. var opts = jQuery.extend(defaults,options);
  9.  
  10. return this.each(function(index) {
  11. if(opts.inverted) {
  12. jQuery(this).prepend(itemsLength+opts.delimiter);
  13. itemsLength--;
  14. } else {
  15. jQuery(this).prepend((index+1)+opts.delimiter);
  16. }
  17. });
  18. };
  19.  
  20. /***TO USE***/
  21.  
  22. $('your element').autoNumbering({inverted:true,delimiter:". "});

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.