Matei Mihai Matei Mihai - 3 months ago 20
jQuery Question

How to add a callback function to the addClass method of jQuery?

I'm using Prettify from Google and Markdown and I want each time I find a

pre
code added in the markdown
textarea
to call again the
prettyPrint()
function.

This is my actual code:

if($('#wmd-preview').length > 0) {
$('#wmd-preview').on('DOMNodeInserted DOMNodeRemoved',function(){
$(this).find("pre").not('.prettyprint').addClass("prettyprint");
});
}


But I want something like:

$(this).find("pre").not('.prettyprint').addClass("prettyprint",function(){
prettyPrint();
});


Is there any possible way to achieve this?

Answer

As far as I understand, you need this:

$(this).find("pre").not('.prettyprint').each(function(){
   $(this).addClass("prettyprint");
   prettyPrint();
})
Comments