According to the jQuery API's Documentation I'm using the correct event handler.
I'm also aware of the IE issue stated as well, and I don't care, as this is merely just a playful experiment.
Note: Attempting to change the
type
property (or attribute) of aninput
element created via HTML or already in an HTML document will result in an error being thrown by Internet Explorer 6, 7, or 8.
So I have been trying to get this to work and I'm left with a few questions:
- Is this possible?
- If so what am I doing wrong & how can I fix it?
Edit
My intention is to change .selected
's tag from a span
to whatever the user specified. I originally used a button
as an example, but I saw how easily my post was misunderstood. As my intentions are to change the span
tag to anything from a button
to a input[type=text]
element. All depending on what the user types in a textbox.
I don't see how replaceWidth is going to help me in this case. How can I understand more about this?
$(document).ready(function() {
// Show active tag
$(".activetag").html( $(".selected").prop("tagName").toLowerCase() );
// Change selected element's tag
$(".convert").on("keyup", function() {
$(".selected").replaceWidth( $("div") ).html( $(".selected").html() );
});
// Show selected element's code
// ex. <span class="selected">Hello world</span>
$(".code").val( $(".selected").html() );
});
<!DOCTYPE html>
<html>
<head>
<title>new document</title>
<meta charset='utf-8'>
<meta name='viewport' content='initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='IE=9' />
<link type='text/css' rel='stylesheet' href='http://necolas.github.io/normalize.css/3.0.1/normalize.css'/>
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'></script>
</head>
<body>
<div align="center">
<span class="activetag">Hello world</span><br />
<input type="text" class="convert"><br />
<span class="selected">Hello world</span><br />
<textarea class="code"></textarea>
</div>
</body>
</html>