Reputation: 59
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();
Upvotes: 0
Views: 885
Reputation: 5831
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>
Upvotes: 2