In my script, I have a iframe
.
<iframe id="result" name="result" src="url_do_documento" sandbox="allow-same-origin"></iframe>
The file that iframe
references, contains a h1
element, 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'm 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
with a input
, so that its value could be changed, then altered should happen exactly the inverse.
The commented code is what just is not working, the onBlur
event is not triggered and input
is not replaced by h1
.
Does anyone have any idea how to do this element replacement?
UPDATE:
I tried both forms of the answers and did not get the expected result: /
When viewing code execution through the browser console, h1 has an event bound to it, as you can see:
Butwhenyousubstitutefortheinput,itdoesnothaveatrailerevent,sonothinghappens.