Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument data-target to popover #13029

Closed
kaystrobach opened this issue Mar 12, 2014 · 10 comments
Closed

Add argument data-target to popover #13029

kaystrobach opened this issue Mar 12, 2014 · 10 comments

Comments

@kaystrobach
Copy link

<button data-target="#someSuperDuperStyledDiv" type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="left" >
  Popover on left
</button>
<div id="someSuperDuperStyledDiv">I'm the html popover content</div>

Having this we can use popovers to display html content easier and it is better to read than the data-content attribute, which is currently available.

@drewlustro
Copy link

I also wanted this and accomplished it fairly straightforward as a content function you can pass to $.popover()

$('[rel=popover]').popover({
    html: true,
    content: function () {
        var targetId = $(this).attr('data-target');
        return $(targetId).html();
    }
});

@kaystrobach
Copy link
Author

thank you @drewlustro .
sure, but having sth. nativly integrated allows easier updating / upgrading ...

@drewlustro
Copy link

Not arguing against your request, just giving you a way to do it in the
meantime if you need it for your project.

On Tuesday, April 29, 2014, Kay Strobach notifications@github.com wrote:

thank you @drewlustro https://github.com/drewlustro .
sure, but having sth. nativly integrated allows easier updating /
upgrading ...


Reply to this email directly or view it on GitHubhttps://github.com//issues/13029#issuecomment-41640298
.

@kaystrobach
Copy link
Author

👍 i understood. never wanted to offend you.

@drewlustro
Copy link

👍 @kaystrobach did that help you out? I just implemented a bunch of code that heavily employs data-target.

It's maybe worth noting that complex content with additional javascript handlers inside popover content must be attached to the DOM after bootstrap fires its shown.bs.popover event. So if you have content in there that does anything custom or special besides <a> links etc, just note that your copied return $(targetId).html() from the popover content function will be eventless.

@kaystrobach
Copy link
Author

in my case it is a valid solution, even if i used it before ...
But having event's would not be bad at all 😄

@cvrebert cvrebert added this to the v3.3.0 milestone Jun 28, 2014
@mdo
Copy link
Member

mdo commented Aug 2, 2014

Punting to the v4 checklist.

@mdo mdo closed this as completed Aug 2, 2014
@eguneys
Copy link

eguneys commented Aug 7, 2014

I thought data-target is supposed to tell which element the popover points at. Like in collapse.

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 7, 2014

@eguneys Yeah, we'd likely name it something else. The core idea is reasonable though.

@emersion
Copy link

emersion commented Feb 9, 2015

If you want to keep event binding, you can use this:

$('[rel=popover]').each(function () {
    var targetId = $(this).attr('href');
    var target = $(targetId).detach();

    $(this).popover({
        html: true,
        content: function () {
            return target;
        }
    });
});

@mdo mdo mentioned this issue May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants