Edit this page

up.fragment up:fragment:keep
DOM event

This event is emitted before an existing element is kept during a page update.

Event listeners can call event.preventDefault() on an up:fragment:keep event to prevent the element from being persisted. If the event is prevented, the element will be replaced with a fragment from the response.

Example

The following would only keep an <audio up-keep> element as long as it plays the same song (as identified by the tag's src attribute):

up.on('up:fragment:keep', 'audio', function(event) {
  if (element.getAttribute('src') !== event.newElement.getAttribute('src')) {
    event.preventDefault()
  }
})

Tip

You may also define an up:fragment:keep listener in HTML using an [up-on-keep] attribute.

Properties

event.preventDefault()

Prevents the fragment from being kept.

The fragment will be replaced with event.newFragment.

event.target Element

The fragment that will be kept.

event.newFragment Element

The discarded element.

event.newData Object

The data attached to the discarded element.

event.renderOptions Object

An object with render options for the current fragment update.