2
      my html content is in iframe.
        <iframe id="test" name=""src="test.html">
        .....content from test.html

      </iframe>

test.html(in my server) has a link like

         <div id="division"><a  href="www.google.com"></a></div>

jquery

              $(document).ready(function() {
           var value=$("#division").find('a').attr('href');
        alert(value);
                }

question:alert(value) returns undefined

VDN
  • 85
  • 1
  • 9
  • possible duplicate http://stackoverflow.com/questions/1654017/how-to-expose-iframes-dom-using-jquery – terafor Jun 03 '13 at 22:34

1 Answers1

3

Once the iframe has loaded, you'll have to use contents() to get the content, and then search and get the href property of the anchor, and the loaded content can't be cross domain, same origin policy etc :

$(document).ready(function() {
    $('#test').on('load', function() {
        var value = $(this).contents().find("#division a").prop('href');
        alert(value);
    });
});
adeneo
  • 312,895
  • 29
  • 395
  • 388