3
In my script, I have one iframe
.
<iframe id="result" name="result" src="url_do_documento" sandbox="allow-same-origin"></iframe>
The file q o iframe
reference, contains an element h1
, as in the structure below:
<!DOCTYPE>
<html>
<head></head>
<body>
<h1 class="pf-change-h1">H1 que pretendo alterar!!</h1>
</body>
</html>
to access H1, I am using Jquery as follows:
$("#result").load(function(){
var h1 = $("#result").contents().find(".pf-change-h1");
h1.click(function(){
$(this).replaceWith("<input type='text' value='" + $(this).html() + "' class='pf-change-h1' />");
});
/*h1.blur(function(){
$(this).replaceWith("<h1 class='pf-change-h1' >" + $(this).html() + "</h1>");
});*/
});
The purpose of this code would be to replace the element h1
by a input
, so that its value could be changed, after changing it should happen exactly the opposite.
The commented code is the one that just isn’t working, the event onBlur
is not fired and the input
is not replaced by h1
.
Does anyone have any idea how to make this substitution of elements?
UPDATE:
I tried both forms of answers and did not get the expected result :/
When viewing code execution from the browser console, H1 has an event attached to it, as you can see:
But by replacing it with input, it has no event attached, causing nothing to happen.
This iframe is in the same domain?
– Sergio
Yes, in the same domain
– Thomerson Roncally
Whether or not input containing the same class as H1?
– Thomerson Roncally
If you can use the contentEditable attribute maybe you can edit H1 without having to turn it into input.
– hugomg
You’re missing the object reference. Edit: just answered this :D
– Lucas