// this Is actually 1 a Html Elements.
// $this It's just a variable name, plus $ To show that it's a jquery Object.
// while $(this) It's a transformation, will this The said dom Object to jquery Object, so you can use it jquery Provides method operations.
(function($){
$.fn.hilight = function(options){
debug(this);
var defaults = {
foreground: 'red',
background: 'yellow'
};
var opts = $.extend({}, $.fn.hilight.defaults, options);
return this.each(function() {
// this Is actually 1 a Html Elements.
// $this It's just a variable name, plus $ To show that it's a jquery Object.
// while $(this) It's a transformation, will this The said dom Object to jquery Object, so you can use it jquery Provides method operations.
$this = $(this);
// build element specific options
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
// update element styles
$this.css({
backgroundColor: o.background,
color: o.foreground
});
var markup = $this.html();
// call our format function
markup = $.fn.hilight.format(markup);
$this.html(markup);
});
};
// define our format function
$.fn.hilight.format = function(txt) {
return '<strong>' + txt + '</strong>';
};
// The plug-in defaults
$.fn.hilight.defaults = {
foreground: 'red',
background: 'yellow'
};
function debug($obj) {
if (window.console && window.console.log){
window.console.log('hilight selection count: ' + $obj.size());
}
};
})(jQuery)