---
name: "HTMLDocument.addInlineElementAt"
section: "3kaya"
platform: "linux"
package: "kaya"
version: "0.4.4-6.2"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/HTMLDocument.addInlineElementAt"
---

# HTMLDocument.addInlineElementAt(3kaya)

Wrap existing text in an inline element

## NAME

HTMLDocument::addInlineElementAt - Wrap existing text in an inline element

## SYNOPSIS

**ElementTree addInlineElementAt(** *ElementTree block, InlineElement inline, Int startpos, Int endpos* **)**

## ARGUMENTS

**block** The element to add to

**inline** The inline element to add

**startpos** The start position for the inline element

**endpos** The end position for the inline element

## DESCRIPTION

Encloses existing text within an element within an inline element. The characters from **startpos**  to **endpos**  inclusive (with a starting index of zero) will be included in the inline element.

-

   p = addParagraph(parent,"abcdefghijklmnopqrstuvwxyz");\
    void(addInlineElementAt(p,Emphasis,5,10));\
    void(addInlineElementAt(p,StrongEmphasis,6,8));\
    // \<p\>abcde\<em\>f\<strong\>ghi\</strong\>jk\</em\>lmnopqrstuvwxyz\</p\>

An **HTMLDocument.InvalidNesting (3kaya)** Exception will be thrown if the element being added to cannot contain inline elements, or an impossible nesting situation would be created. An **HTMLDocument.InvalidRange (3kaya)** Exception will be thrown if the **startpos**  or **endpos**  are outside the text contents of the block.

-

   p = addParagraph(parent,"abcdefghijklmnopqrstuvwxyz");\
    void(addInlineElementAt(p,Emphasis,5,10));\
    void(addInlineElementAt(p,StrongEmphasis,6,15));\
    // exception thrown

The **firstOccurs**  function is useful for highlighting a particular word within a string.

-

   haystack = getAllText(element);\
    npos = firstOccurs(needle,haystack);\
    if (npos \< length(haystack)) {\
        try {\
            added = addInlineElementAt(element,Emphasis,npos,npos+length(needle)+1);\
        } catch(InvalidNesting(details)) {\
            // probably overlapping elements\
        }\
    }

## AUTHORS

Kaya standard library by Edwin Brady, Chris Morris and others (kaya@kayalang.org). For further information see http://kayalang.org/

## LICENSE

The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.

## RELATED

**HTMLDocument.InlineElement (3kaya)**

**HTMLDocument.appendInlineElement (3kaya)**

**Strings.firstOccurs\_1 (3kaya)**
