How to change background-color of a button inside an Iframe with Jquery

1

Good afternoon, I'm trying to run a function inside an iframe to change the background-color of a button that is in another Iframe, I started to do some testing and I could not get anyone to help me. >

//Iframe A
<hmtl>
<head>
<script>
function mudarCorBotao ()
{$(":button").contents("iFrameBotoes").find("btnId").css({"background-color": "yellow"});
</script>
<head>
<body>
codigos...
</body>
</html>

This is the status of iframe B

<div id="divBotoes"> <iframe id="iFrameBotoes"></iframe></div>

The two iframes are in the same html (parent), so I need iframe A to make changes to Iframe B, the buttons are cast in a C # function and inserted in iframe B.     

asked by anonymous 21.09.2018 / 21:22

1 answer

0

You can do the following:

  • Use $('#iFrameBotoes', parent.document) to select the parent document and fetch iframe B by its id ;

  • Select iframe contents with .contents() ;

  • Find the button by its id with .find("#btnId") ;

  • Change the CSS with .css({"background-color": "yellow"}) .

The function will look like this:

function mudarCorBotao(){
   $('#iFrameBotoes', parent.document)
   .contents()
   .find("#btnId")
   .css({"background-color": "yellow"});
}
    
21.09.2018 / 22:06