Matt
Matt

Reputation: 26971

Extending the Javascript prototype for all items of a certain class?

What is the best way to extend the Javascript prototype for all items of a certain class? I want all textboxes (input) of a certain class to have

function OnValueChange()
{
// Wow!
}

This way I can add onblur="OnValueChange" to my input.

I can do it on an individual object by modify the prototype, but I am wondering if there a way to it for all items of a certain class or other distinguishing attribute.

I have access to jquery in my project

Upvotes: 1

Views: 75

Answers (1)

scrappedcola
scrappedcola

Reputation: 10572

If you have access to jQuery then just use :

$(".inputClassNameHere").live("blur", function(){OnValueChange();});

This way all current and future inputs with class inputClassNameHere will call OnValueChange when the blur event is triggered.

Upvotes: 2

Related Questions