Reputation: 463
I have this code in an iframe:
HTML CODE
<iframe id="iframe">
.......
<div id="message-box" class="error">
No flights found
</div>
.......
</iframe>
I want to run a JavaScript function when the iframe completely loads and get this inner div and its text. How can I do that?
Here is some code:
JS CODE
var content = $("#iframe").contents().find("#message-box").html();
Upvotes: 1
Views: 4417
Reputation: 28
I don't know your code. But if you have an iframe with "iframe" id, try this;
var content = $('#iframe #message-box').html();
Upvotes: 1
Reputation: 1981
You don't have #
character in your selector. Try replace your code with this:
var content = $("#iframe").contents().find("#message-box").html(); // # added
Upvotes: 0