0

Please Check below code In IE8:

 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
           <script language="javascript" type="text/javascript">
            function btnclick() {
                document.createElement("myTag");
                var testctrl = document.createElement("div");
                testctrl.innerHTML = " <myTag>hai</myTag>";
                document.getElementById("temp").appendChild(testctrl);
alert(testctrl.innerHTML);
            }
        </script>
        <style type="text/css">
        myTag
        {
            background-color:Blue;
            height:20px;
            width:100px;
        }
        </style>
    <title>

    </title></head>
    <body>
        <input type="button" id="tbtn" onclick="javascript:btnclick();return false;" value="ClickMe"/>
        <div id="temp" >
        </div>
    </body>
    </html>

i got value from myTag Like As :

**testctrl.innerHTML contain as Follow**

"hai</MYTAG>"

So how can i use in this code for IE? I Should be want the tags Like as not like as

2 Answers 2

3

Try:

var mytag = document.createElement("myTag");
var testctrl = document.createElement("div");
mytag.innerHTML = "hai";
testctrl.appendChild(mytag);
document.body.appendChild(testctrl);
2
  • Thats ok but i want create from Html string
    – RGA
    Oct 20, 2012 at 8:54
  • @Rameshathish, IE 8 just does not understand custom tags as creating elements. You need to call document.createElement(...) at least once, for each custom tag, before IE 8 starts recognizing the tags too. Oct 20, 2012 at 12:02
0

Using custom tags is always kind of wired because browser differ in handling custom tags. If you are working with xhtml and xhtml headers you should add your namespace to the html and the element, but mixing custom tags with xhtml tags is something I would not do. I once used custom namespace attributes what did a good job but therefor you should use the html5 data attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.