I know i have an error on this and i feel so new but i need to ask for help. Here is the code i need to fix. I get the follow error: Uncaught TypeError: Cannot read property 'find' of undefined
<div class="plugin" data-plugin="true"></div>
<script>window.jQuery || document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"><\/script>')</script>
<script>
;(function($){
var namespace = 'plugin';
function Plugin(element,options){
this.settings = options;
this.version = '0.0.1';
this.$element = element;
this.init();
}
Plugin.prototype.formatString = function(key,val){
return this.$element.find('ul').append('<li><strong>' + key.toUpperCase() + ':</strong> ' + val + '</li>');
};
Plugin.prototype.printSettings = function(){
this.$element.append('<ul>');
$.each(this.settings, this.formatString);
};
Plugin.prototype.init = function(){
this.printSettings();
};
$('.plugin').each(function(key,val){
if (!$(this).data[namespace]) $(this).data[namespace] = new Plugin($(this),$(this).data());
});
})(window.jQuery);
</script>
this.$element.find('ul')
seems to be the code causing the error. I have tried to add empty <ul></ul>
tags to the empty div but that didn't do anything. I feel the .find
is not deprecated and it looks like i formatted this correctly but i bet that i am wrong.
').append('- ' + key.toUpperCase() + ': ' + val + '
');
};
This seems to be the code causing the error. I have tried to add empty
– user2025730 Apr 11 '16 at 12:23tags to the empty div but that wouldnt do anything. I feel the .find is not deprecated and it looks like i formatted this correctly but i bet that i am wrong. ughh
but there is not one in the empty div.
– user2025730 Apr 11 '16 at 12:27').append('- ' + key.toUpperCase() + ': ' + val + '
');
};
– user2025730 Apr 11 '16 at 12:34