vineet sah vineet sah - 1 year ago 168
CSS Question

How to change/add CSS inside of iframe by jQuery

I want to add css properties in a iframe div by using jQuery but it's not working.

Html Code:-

<iframe id='iframeId' src='api.php?abc=xyz..'>
<div class='change-class'> //require <div class='change-class' style='background-color:black'>



JS Code:-

I try below code but doesn't get any result.


Jai Jai
Answer Source

For this the iframe src document should also have to be on same domain to access iframe's dom nodes, if you have both pages on same domain then you can do this:

$("#iframeId").contents().find(".change-class").css('background-color', 'black');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download