Title: Change element style on a image inside a iframe
Tags: javascript;jquery;css
Question: Is there a way to change the element-style of the img inside the iframe using jquery. The iframe epubjs-iframe change the id on every page load. What I want is to change the style = heigh="98%" to max-height:467 and width:auto on every page load.
Html-code
Comment: Please post your code here.

Comment: I am using epubjs from futurepress. And when I load the cover page the cover image splits up and isnt responsive. So by using inspect element in chrome I change the values   to max-height: 467 and width:auto. Since I cant reach the iframe from my internal css I was wondering if its possible to use jquery on every load and change the element.style to the values which works.


Here is another answer: Not know if it is the case here, but when working with iframes You may need to overcome Same Origin Policy: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
You can use PostMessage for cross-frame communication. To do so:
You need to be in control of the code both host page and embedded one
Or use the PostMessage API provided by page You want to embed
More about PostMessage: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Here is another answer: Yes, IF the src of your iframe is pointing to SAME domain.
var iframe = $("#iframe"); // Selector to get the iframe
$("#elemInIframe", iframe.contents()).css("color", "blue"); //Or whatever method you want
And Of course, if the src of iframe is in different domain, due to security reasons, You will not be able to access the contents in javascript. Sorry about the same!!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:05/29/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><css>', 'Title': 'Change element style on a image inside a iframe', 'ViewCount': 887, 'id': 37510232, 'user_AboutMe': '', 'user_AccountId': 6252266.0, 'user_DisplayName': 'rallesport', 'user_Reputation': 28.0, 'user_Views': 1.0, 'user_id': 4861983.0}}