# insert\_top

Source: https://zotonic.com/docs/1336/insert_top

URI: https://zotonic.com/id/1336

Language: en



Inserts HTML before the contents of an HTML element.

Adds a template or a literal HTML text before the existing content.

Example:

```django
<div id="mydiv"><p>Bye Bye.</p></div>
{% button text="hello" action={insert_top target="mydiv" text="<p>Hello World!</p>"} %}
```

After the button is clicked, the contents of the div will be &lt;p>Hello World!&lt;/p>&lt;p>Bye Bye.&lt;/p>.

Another example, now rendering a template:

```django
<ul id="mylist"><li>Some item</li></li>
{% button text="hello" action={insert_top target="mylist" template="_list_item.tpl" id=42} %}
```

This inserts the output of the template \_list\_item.tpl above the existing &lt;li/>. All arguments to the update action are also arguments to the template.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1336?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1336?language=en>)
