如何在jQuery的addClass方法中添加回调函数? [英] How to add a callback function to the addClass method of jQuery?

查看:594
本文介绍了如何在jQuery的addClass方法中添加回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google和Markdown的Prettify,每次我想在markdown textarea中添加pre代码时再次调用prettyPrint()函数.

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.

这是我的实际代码:

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

但是我想要类似的东西

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

有没有办法实现这一目标?

Is there any possible way to achieve this?

推荐答案

据我了解,您需要这样做:

As far as I understand, you need this:

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

这篇关于如何在jQuery的addClass方法中添加回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆