> From: pedalpete
> 
> Personally, I try not mixing jquery components with standard 
> javascript (like your document.createElement), with the 
> exception of within functions.
> Somebody else can probably comment on what is appropriate.

Well, all jQuery code *is* standard JavaScript. jQuery itself is just a
bunch of JavaScript code, after all.

I think you meant "direct DOM manipulation". Actually, that's fine to mix
with jQuery code, and in fact encouraged.

For example, if you have a DOM element in "this", you can get its ID with:

    $(this).attr('id')

or:

    this.id

That's not just simpler, but much faster.

Now you're right, for the case in question here, I would use the simpler
jQuery code instead of document.createElement. I just wanted to comment on
the general question of mixing the two.

> I'd write this something like
> [code]
> $('#container').append('<iframe id="commentiframe" />'); 
> $('#commentiframe').attr('src', 'http:LINK');
> [/code]
> 
> that should create the iFrame and get a document.

That's fine for an iframe that loads an external HTML file. Geuis wants to
create an iframe with completely dynamic content generated from JavaScript.

> But you say you want to create an iFrame and then put
> data into it.
> 
> I'm not sure you can do that, or you would be able to inject 
> stuff into somebody elses page, theoretically on there 
> server. THOUGH I COULD BE VERY WRONG on this.

Not a problem at all. When you create a dynamic iframe and write content
directly to it, it belongs to the same domain as the host page. That's what
allows you to manipulate its content directly - it's as if you'd loaded an
iframe from an HTML page in the same domain, not some foreign domain.

> If you are just trying to get data and display it, why not 
> just update a div?

All sorts of reasons. For example, you may have some special content that
you have to generate dynamically, and it requires its own oddball JavaScript
code that messes with Object.prototype and other JavaScript objects, which
thoroughly breaks jQuery and other code that you try to load in the same
page. You can fix that by isolating the bad code in its own iframe.

-Mike

Reply via email to