tags:

views:

24

answers:

1
+2  Q: 

jQuery selector

I have the following markup that will be repeated for several questions

<p id="questionOne">What are your tasks?</p>

<p id="copyLastYear"><a href="#">Copy from last year</a></p>

<div id="anserOne">
  <div class="cleditorMain">
    <div><!-- Editor tags here --></div>
    <iframe>
      <html>
        <head></head>
        <body></body>
      </html>
    </iframe>
  </div>
</div>

When someone clicksthe copy from last year link I need to set the html in the body with the details from last years answer.

The problem I'm having is selecting the body tag

I tried the following but with no luck

$('#answerOne .cleditorMain iframe html body').html('<p>New HTML value</p>');

Can anyone help with the selector part of this please.

Thanks

+2  A: 

You need to use contents(). Something like this should work.

$('#answerOne .cleditorMain iframe').contents().find('body').html('<p>New HTML value</p>');
meder
Perfect. Worked like a charm.Thank you vey much for your help.