Skip to main content
AddTag method

Adds an element behavior to a namespace.


HRESULT retVal = object.AddTag(bstrTagName, lFlags);


bstrTagName [in]

Type: BSTR

The name of the element behavior to add.

lFlags [in]

Type: LONG

A LONG that specifies one of the following ELEMENTDESCRIPTOR_FLAGS enumeration values:


Default. Creates a usual element behavior.


Creates a literal content element behavior.


Internet Explorer 6 and later versions, creates a nested literal content element behavior.

Return value


If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.


When MSHTML determines that an object tag in a Web page implements a behavior, it first calls IElementNamespaceFactory::Create, which enables the behavior to add all of its tags to the namespace. MSHTML recognizes each object tag that implements a behavior. When MSHTML encounters a custom element, it can identify which object tag to reference for its implementation.

MSHTML maintains an association between each object tag and its corresponding element behavior, so that several custom tags can be added to a namespace without interference.

In Internet Explorer 6, creates nested literal content element behaviors.


The following example shows how to add the "MyTag" element behavior to the namespace pointed to by pNamespace.

BSTR bstrTagName = SysAllocString(L"MyTag");
HRESULT hr = pNamespace->AddTag(bstrTagName, 0);