tags:

views:

52

answers:

4

I have the following HTML code:

<body>
  ...
  <div id="users">
      <iframe src="http://control.intranet/userlist.php" height="100">
  </div>
  ...
</body>

Where the //control.intranet/userlist.php loads a list of users from our intranet control panel.

This list looks like this:

<div class="user">
    <span class="name">Boda Cydo</span>
    <span class="ip">10.42.12.2</span>
    ...
</div>
<div class="user">
     ...
</div>
...

Now I want to format how the userlist looks, so I try to match elements in it with jQuery:

$("#users .name").css("background-color", "#FF0000")

But it never matches a single .name.

I even tried just $("#users").length and it returns 0.

This makes me think that I can't edit DOM elements loaded via iframe with jQuery. Is that true? If so, how do I edit CSS of elements that are loaded via iframe?

Thanks, Boda Cydo.

A: 

Please have a look at Iframe Plugin for jQuery http://ideamill.synaptrixgroup.com/?p=6

sushil bharwani
A: 

Quick googling gave me : http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/

CodeReaper
+1  A: 

The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.

From: http://api.jquery.com/contents/

Jochem
A: 

try

$("#iframeid").contents().("#users .name").css("background-color", "#FF0000");

it will only work if your iframe and main page belongs to same domain.

Yogesh
Is there any way to go cross-domain?
bodacydo