Javascript 如何修改此jQuery以将活动类添加到所选链接?

Javascript 如何修改此jQuery以将活动类添加到所选链接?,javascript,jquery,Javascript,Jquery,有人能解释一下我是如何修改这段代码的,这样它就可以向所选链接添加一个“活动”类,以及它是如何工作的吗?请提前感谢您以下代码将活动类添加到单击的链接: jQuery(document).ready(function() { jQuery(".page-contents div").hide(); // Show chosen div, and hide all others jQuery("a").click(function (e) {


有人能解释一下我是如何修改这段代码的,这样它就可以向所选链接添加一个“活动”类,以及它是如何工作的吗?请提前感谢您

以下代码将
活动
类添加到单击的链接:

jQuery(document).ready(function() {
    jQuery(".page-contents div").hide();
          // Show chosen div, and hide all others
        jQuery("a").click(function (e) {
            //e.preventDefault();
            jQuery("#" + jQuery(this).attr("class")).show().siblings('div').hide();
        });
   });
jQuery(document).ready(function() {
    jQuery(".page-contents div").hide();
    // Show chosen div, and hide all others
    jQuery("a").click(function (e) {
        //e.preventDefault();
        //jQuery("#" + jQuery(this).attr("class")).show().siblings('div').hide();
      jQuery(this).addClass("active");
    });
});