Home Manual Reference Source
import DOMReplaceWithSameElementFromUrl from 'ievv_jsbase/lib/dom/DOMReplaceWithSameElementFromUrl'
public class | source

DOMReplaceWithSameElementFromUrl

Extends:

DOMReplaceDOMReplaceFromUrl → DOMReplaceWithSameElementFromUrl

Extends DOMReplaceFromUrl to replace the element with the same element from the server response.

This is intended to be used if you request a full page from the server to replace a single element in your document.

Example

Lets say you have a /pages/test that produce the following HTML:

<html>
    <body>
        <div id="id_something">
            Initial data.
        </div>
    </body>
</html>

And you would like to replace the current content of the id_something element with updated data from the server:

let domReplace = new DOMReplaceWithSameElementFromUrl('id_something');
domReplace.replaceInnerHtml('/pages/test')
    .then((htmlString, response) => {
       console.log(
           `successfully replaced the current content of id_something with: ${htmlString}`);
       console.log(`The full response from the server was: ${response.toString()}`);
    })
    .catch((error) => {
       console.error(`An error occurred: ${error.toString()}`);
    });

Method Summary

Public Methods
public

Overridden to extract the innerHTML of the element with ID matching DOMReplaceWithSameElementFromUrl.elementId.

Inherited Summary

From class DOMReplace
public

The DOM element.

public

The element DOM ID.

public

appendInnerHtml(htmlString: string)

Append innerHTML to the element.

public

prependInnerHtml(htmlString: string)

Prepend innerHTML to the element.

public

replaceInnerHtml(htmlString: string)

Replace innerHTML of the element.

From class DOMReplaceFromUrl
public

Append to the innerHTML of the element with data from a GET request to an URL.

public
public

Prepend to the innerHTML of the element with data from a GET request to an URL.

public

Replace innerHTML of the element with data from a GET request to an URL.

Public Methods

public extractHtmlStringFromResponse(response: *): string source

Overridden to extract the innerHTML of the element with ID matching DOMReplaceWithSameElementFromUrl.elementId.

Override:

DOMReplaceFromUrl#extractHtmlStringFromResponse

Params:

NameTypeAttributeDescription
response *

See DOMReplaceFromUrl#extractHtmlStringFromResponse

Return:

string

The extracted HTML string.