Jeffson Jeffson - 5 days ago 6
Javascript Question

Convert Jquery plugin Into Javascript

Is there anybody here who knows the Javascript-equivalent or the Javascript version of the code below?

(function($) {
$.fn.green = function() {
var selector = this;
selector.css('color' , 'green');
};
})(jQuery);


And so on I will call this :

$('p').green();

Answer

You can do it with prototype method, you wan override or set basics JS methods to Elements,Objects,type etc...

Example

Element.prototype.Color = function(color)
{
  this.style.color=color;
}

Element.prototype.Green = function()
{
  this.style.color="green";
}

document.getElementById("myid").Color("red");
document.getElementById("secondid").Green();
<div id="myid">Div element</div>
<div id="secondid">Second div</div>

Comments