What is method chaining in jquery

Method chaining in jquery is to apply multiple method in one go over an element. See below example..

var el=$(‘#mydiv’):

el.removeclass(‘oldclass’).addclass(‘class1’).CSS(‘color’:’red’);

In above example we removed a class then added another class and then applied a css. We didn’t applied seperately each method instead chained it.

Leave a comment