> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/modularity/ui-compatibility/reference/components/div.md).

# Div

Generates a dynamic HTML div element that can be updated asynchronously via AJAX.

## Syntax

```boxlang
<bx:div 
    bind="string"
    bindOnLoad="boolean"
    id="string"
    onBindError="string"
    tagName="string"
    class="string"
    style="string">
    <!-- Optional body content -->
</bx:div>
```

## Attributes

| Attribute     | Type      | Required | Description                                                | Default        |
| ------------- | --------- | -------- | ---------------------------------------------------------- | -------------- |
| `bind`        | `string`  | No       | Bind expression that provides content for the div via AJAX | `""`           |
| `bindOnLoad`  | `boolean` | No       | Whether to execute bind expression when tag first loads    | `true`         |
| `id`          | `string`  | No       | HTML ID attribute of the generated div tag                 | Auto-generated |
| `onBindError` | `string`  | No       | JavaScript function to handle bind expression errors       | `""`           |
| `tagName`     | `string`  | No       | HTML tag name to generate                                  | `"div"`        |
| `class`       | `string`  | No       | Additional CSS classes                                     | `""`           |
| `style`       | `string`  | No       | Additional CSS styles                                      | `""`           |

## Examples

### Basic div with static content

```boxlang
<bx:div id="myDiv" class="content-area">
    <p>This is static content</p>
</bx:div>
```

### AJAX-enabled div with bind expression

```boxlang
<bx:div id="dynamicDiv" bind="cfc:myComponent.getData()" bindOnLoad="true" />
```

### Custom tag name

```boxlang
<bx:div tagName="section" class="main-section">
    <h2>Section Content</h2>
</bx:div>
```

### With error handling

```boxlang
<bx:div bind="url:data.bxm" onBindError="handleError" />

<script>
function handleError(error) {
    console.log("AJAX error:", error);
}
</script>
```

## Usage Notes

* When using the `bind` attribute, the component cannot have body content
* Valid `tagName` values: div, span, p, section, article, aside, header, footer, main, nav
* If `bindOnLoad` is true, the div will show a loading indicator until AJAX content loads
* The component automatically adds CSS classes for styling and JavaScript functionality

## Related Components

* [AjaxImport](/boxlang-framework/modularity/ui-compatibility/reference/components/ajaximport.md) - Import required AJAX files
* [Layout](/boxlang-framework/modularity/ui-compatibility/reference/components/layout.md) - Layout containers
* [Grid](/boxlang-framework/modularity/ui-compatibility/reference/components/grid.md) - Data grids


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/modularity/ui-compatibility/reference/components/div.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
