views:

24

answers:

1

Currently, I am using jquery to make a certain class/span editable:

$(function(){$('.test').editable({editClass:'tryThis',type:'textarea'})});

That works great. Now, what I would like to do is put the source into an iFrame (ID=iTarget).

How would I access this class now?

I tried:

$(function(){document.getElementById('iTarget').$('.test').editable({editClass:'tryThis',type:'textarea'})});

But that doesn't work, I must be missing something.

+1  A: 

Try the contents() method:

$("#iTarget").contents().find(".test").editable({
    editClass: "tryThis",
    type: "textarea"
});
Douglas
Actually, I plugged it in and it worked, and now it doesn't. In my iFrame, I've got a dv that surrounds everything called "tgt", and then the span of .test is beneath that. Does that make a difference?
John
It sounds like it should still work, find should include all descendants. Do you know what could have changed between the first time and the second time you tried it?
Douglas
Weird... iTarget is my iFrame. <div id="tgt"><p><span class="test">ttttt</span></p></div>
John
iFrame looks like: <iframe src="target.html" width="450" height="500" id="iTarget">
John
I am putting it within the $(document).ready(function() function. Maybe that's the issue?
John
Yes, that could be it. You need to make sure that the iframe has loaded before trying to modify its contents. The iframe will load after the parent page has loaded. Can you move your editable code into the iframe itself? It would make things much easier. You should delay running your code after the iframe's onload event fires.
Douglas
hmmm. that makes sense. I'd rather keep the code out of the iFrame - is there a way to hold of the ready function until the iFrames load?
John
OK - inside the parent page, I put: $('iframe').load(function() { // write your code here.... }that seems to make it work. Many thanks!
John