IE8 lose custom tags
-
13-07-2021 - |
Question
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
Solution
Try:
var mytag = document.createElement("myTag");
var testctrl = document.createElement("div");
mytag.innerHTML = "hai";
testctrl.appendChild(mytag);
document.body.appendChild(testctrl);
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow