Dynamically add a class to Bootstrap's 'popover' container

后端 未结 22 2516
名媛妹妹
名媛妹妹 2020-11-29 18:27

I\'ve thoroughly searched through both StackOverflow and Google, but come up empty. So apologies in advance if this has been asked & resolved already.

NB

22条回答
  •  抹茶落季
    2020-11-29 18:51

    Based on what @bchhun wrote and a lot of head scratching, I felt I should answer my own question, as I got it working. I also noticed this had been favourited and liked, so I hope I'm helping someone else who is a newbie at jQuery like myself.

    In the current Bootstrap build [v2.1.0], the scripts are all consolidated. So if you have included all of the scripts in your build (and not edited any new lines/taken some out), then head to line 1108 of the un-minified .js file. You'll find the following bit of code:

    $tip
      .css(tp)
      .addClass(placement)
      .addClass('in')
    

    You're going to be adding a new line to this, which is:

      .addClass(this.$element.attr("data-class"))
    

    So now whenever you add data-class to the popover call, it will add the attribute to the

    div.

    Now that I see it, it's so obvious :)

提交回复
热议问题