2

I have an iframe content containing multiple classes.i.e, header, footer

I want to apply css styles for these classes dynamically using jquery,

I try to apply only for header in the following way, but how do i apply for footer(if we have multiple classes) dynamically.

$('#iframe').find('.header').css({
            'color': objProp.cssstyles['header']['color'],
            'background-color': objProp.cssstyles[pageSection]['background']                
        });

i have a json data,

var objProp = {            
        "cssstyles": {
            "header": {
                "background": "#FFFFFF",
                "color": "#959597"
            },               
            "footer": {
                "background": "#2b9ef0",
                "color": "#f7992d"                  
            }
        }
    };
1
  • Did you manage to change any styles of anything yet in the iframe? By the looks of the code you showing, it doesn't look like you'd succeed with the header.Need the HTML of the page and the HTML of the page inside the iframe. If you do not control the page within the iframe, then forget the whole idea. Commented Apr 12, 2016 at 7:51

1 Answer 1

1

You can refer to below code for an idea. This demo HTML doesn't contains any iframe but i think you can manage it as per your HTML Please refer to jQuery's .css() documentation for further help.

var objProp = {            
        "cssstyles": {
            "header": {
                "background": "#FFFFFF",
                "color": "#959597"
            },               
            "footer": {
                "background": "#2b9ef0",
                "color": "#f7992d"                  
            }
        }
    };

$(document).ready(function(){
  var cssStyles = objProp["cssstyles"];
  for(var key in cssStyles){
    var cssObjToApply = cssStyles[key];
    $("."+key).css(cssObjToApply);
  }
});  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="header">
  this is header
</div>  
<div class="footer">
  this is footer
</div>  

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.