Is it possible to edit DOM elements that get loaded via an <iframe> with jQuery?
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 look开发者_运维问答s, 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.
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/
try
$("#iframeid").contents().("#users .name").css("background-color", "#FF0000");
it will only work if your iframe and main page belongs to same domain.
Quick googling gave me : http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/
精彩评论