> For the complete documentation index, see [llms.txt](https://docs.jentis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jentis.com/use-cases-and-tutorials/adding-custom-html-codes.md).

# Adding Custom HTML Codes

With the JENTIS Code elements, you can use JavaScript code snippets that activate client-side (on the frontend, effectively on the user's device). This is a powerful tool in itself, but what if my requirement is a bit more "straightforward" HTML? Copy-pasting the markup code into JavaScript will not work. However, we have a workaround coming for you.

### Prerequisite <a href="#addingcustomhtmlcodes-prerequisite" id="addingcustomhtmlcodes-prerequisite"></a>

Let's assume we have an HTML tag that must be implemented on our website. The following might be a possible candidate:

{% code overflow="wrap" lineNumbers="true" %}

```html
<script type="text/javascript" data-key="1" src=https://cdn.example.com/deliver/some.js async></script>
```

{% endcode %}

The idea here is to transpose this markup to a simple and readable JavaScript pendant that will paint such an element to your frontend website. This is effectively the same as just copy-pasting it to a tag management solution (where the input possibly was "Custom HTML").

### Transposing HTML to JavaScript Code <a href="#addingcustomhtmlcodes-transposinghtmltojavascriptcode" id="addingcustomhtmlcodes-transposinghtmltojavascriptcode"></a>

Go to the JENTIS "Server Tag Manager: Codes" section to implement a new code element.

<figure><img src="https://2315305008-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy15ncufYr341K5U8q6Of%2Fuploads%2FtAYiEGIbex7IcGZsiIip%2Fimage.png?alt=media&amp;token=5194db4b-7665-4fc9-8894-0c00afdf7c0d" alt=""><figcaption></figcaption></figure>

(Click "Add New Code", give it a name, and paste the following code into it)

With the magic of JavaScript, we can create the same HTML element with the following code:

{% code lineNumbers="true" %}

```javascript
// create the script tag
let scriptTag = document.createElement("script");

// set the attributes for the script tag
scriptTag.setAttribute("type", "text/javascript");
scriptTag.setAttribute("data-key", "1");
scriptTag.setAttribute("src", "https://cdn.example.com/deliver/some.js");

scriptTag.async = true;

// Append the script tag to the head
document.head.appendChild(scriptTag);
```

{% endcode %}

So any attribute from the "\<script ...>" is set via "setAttribute('name', 'value');". You can adjust this section according to your requirements. If your HTML element has different and/or other attributes, you must add the corresponding lines of code, just like the other "scriptTag.setAttribute" function calls—line by line. Further, the last line of code "document.head.appendChild()" will make sure the according element is painted to the site, and hence the user's browser will load the according source you just defined.

#### Adding an IMG-Tag <a href="#addingcustomhtmlcodes-addinganimg-tag" id="addingcustomhtmlcodes-addinganimg-tag"></a>

If the element you want to add is not a "\<script..>" tag but an image, you only must adjust the "**createElement("script")**" to "**createElement("img")**". Further, you'd need to append this element to the body (not the head): **document.body.appendChild(...)**. Et voilà!

We hope this little workaround will help you create all the necessary elements.


---

# 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://docs.jentis.com/use-cases-and-tutorials/adding-custom-html-codes.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.
