0

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();

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.