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

Asked

Viewed 91 times

1

Good afternoon guys, I’m trying to perform a function inside an iframe to change the background-color of a button that is in another Iframe, I started to do but I’ve done several tests and I can’t 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 iframe condition B

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

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

1 answer

0


You can do the following:

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

  • Select the contents of the iframe with .contents();

  • Search the button for yours 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"});
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.