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

jQuery Popover content loses bound events on second setContent call. #10658

Closed
mauvm opened this issue Sep 16, 2013 · 3 comments
Closed

jQuery Popover content loses bound events on second setContent call. #10658

mauvm opened this issue Sep 16, 2013 · 3 comments
Milestone

Comments

@mauvm
Copy link

mauvm commented Sep 16, 2013

When using a jQuery object as content ($el.popover( { content: $form } )), the form and form elements lose their bound events on second setContent call. When the popover is shown for second time, for example.

This happens because of a jQuery memory leak fix (explanation here, proof here). jQuery's html() method (used in Popover.prototype.setContent) internally uses this.empty().append( value ); and therefore removes the content before appending it again.

I suggest changing:

$tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)

Into something like:

if (this.options.html) {
    $(content).appendTo($tip.find('.popover-content'))
} else {
    $tip.find('.popover-content').text(content)
}

Which fixes the issue. Note that even if content is a jQuery object, it is wrapped again, to support DOM nodes and HTML strings.

@fat
Copy link
Member

fat commented Dec 26, 2013

using appendTo in that way will continue to append you elements to the dom when not using a jquery object… which is the problem with that

@fat
Copy link
Member

fat commented Dec 26, 2013

think it should be something closer to this

$tip.find('.popover-content')[
  this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
](content)

@mauvm
Copy link
Author

mauvm commented Dec 28, 2013

@fat You are absolutely right! Why didn't I think of that? ;)

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

2 participants