6
Why doesn’t it work .contents()
?
How to catch an element inside an iframe as in the jQuery API example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>contents demo</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<iframe src="//api.jquery.com/" width="80%" height="600" id="frameDemo"></iframe>
<script>
$( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" );
</script>
</body>
</html>
Thanks friend, I actually need to insert a class in a div that is inside the iframe. Even the iframe domain is the same. But it’s not working like I said above.
– Weslley Oliveira
@Weslleyoliveira Is the browser console showing an error message? Or is it just "crashing silently"? And in which browser are you testing?
– mgibsonbr
@mgibsonbr So I am working within the C9.io environment, and using the browser Chrome, there is no more error. " silently failing".
– Weslley Oliveira
@Weslleyoliveira Yeah, at first it was supposed to be working... I suggest trying to isolate more error: try doing
console.log
in: to)$( "#frameDemo" )
; b)$( "#frameDemo" ).contents().find( "a" )
before calling thecss
; c) after calling. Edit your answer with these details.– mgibsonbr
Your problem may be on C9.io, you have already run tests on your browser directly ?
– Mauro Alexandre
Mgibsonbr then friend, I’ve done all these table tests, and unfortunately nothing, I’m killing myself with this doubt, thank you for the force. But it has to do with http://c9.io, as our friend @Mauroalexandre says. Except I already tested on http://plnkr.co/, and it didn’t roll, I’ll resume testing.
– Weslley Oliveira
Look friends http://embed.plnkr.co/yiPDhc/preview take the example that is not working.
– Weslley Oliveira