nouman arshad
nouman arshad

Reputation: 463

How to get the content of iframe using jQuery or C#?

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();

error images click here

Upvotes: 1

Views: 4417

Answers (2)

Nakro
Nakro

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

aslawin
aslawin

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

Related Questions