Modify the contents (aka children) of a tag object.

tagAppendChild(tag, child, .cssSelector = NULL)

tagAppendChildren(tag, ..., .cssSelector = NULL, list = NULL)

tagSetChildren(tag, ..., .cssSelector = NULL, list = NULL)

tagInsertChildren(tag, after, ..., .cssSelector = NULL, list = NULL)

Arguments

tag

a tag object.

child

A child element to append to a parent tag.

.cssSelector

A character string containing a CSS selector for targeting particular (inner) tags of interest. At the moment, only a combination of type (e.g, div), class (e.g., .my-class), id (e.g., #myID), and universal (*) selectors within a given simple selector is supported. Note, if .cssSelector is used, the returned tags will have their $children fields flattened to a single list() via tagQuery().

...

a collection of child elements.

list

Deprecated. Use !!! instead to splice into ....

after

an integer value (i.e., subscript) referring to the child position to append after.

Examples

html <- div(a(), h1())
tagAppendChild(html, span())
#> <div>
#>   <a></a>
#>   <h1></h1>
#>   <span></span>
#> </div>
tagAppendChild(html, .cssSelector = "a", span())
#> <div>
#>   <a>
#>     <span></span>
#>   </a>
#>   <h1></h1>
#> </div>

tagAppendChildren(html, span(), p())
#> <div>
#>   <a></a>
#>   <h1></h1>
#>   <span></span>
#>   <p></p>
#> </div>
tagAppendChildren(html, .cssSelector = "a", span(), p())
#> <div>
#>   <a>
#>     <span></span>
#>     <p></p>
#>   </a>
#>   <h1></h1>
#> </div>

tagSetChildren(html, span(), p())
#> <div>
#>   <span></span>
#>   <p></p>
#> </div>

tagInsertChildren(html, after = 1, span(), p())
#> <div>
#>   <a></a>
#>   <span></span>
#>   <p></p>
#>   <h1></h1>
#> </div>