"So in that i have to create a Custom HTML Tag and place it in Document,but not in Body tag"
For that look into createDocumentFragment
and createElement
:
var newfrag = document.createDocumentFragment(),
element = document.createElement("div");
element.innerHTML = "Test";
newfrag.appendChild(element);
This will create the element but not place it within the html body.
RE: custom attributes
Valid custom elements in HTML5 ( <!DOCTYPE html>
) require the name to contain a dash ( - )
And we would need to register and initialise them
var newElement = document.registerElement('custom-element');
var element = document.createElement( new newElement() );
These are a couple of answers to.
- Creating elements outside of the
<body>
- How to use custom attributes ( html5 )
Not sure how far that gets you ... hope helps in someway.
*Update/Fix : * Ashish was able to get the code working on his setup by targeting the <HTML>
tag rather than the <body>
tag and provided the following demo - http://jsfiddle.net/ashish41191/3Bayt/3