0

I have been search for how to add css rules to elements inide an iframe. On most of the SO posts they get the inner elements of iframe tag as:

$("iframe").contents().find("body");

My question is why can't I select the body element inside the iframe as:

$("iframe body");

AFAIK contents jquery method searches for all the text nodes. But isn't body tag an element node? Please explain.

user31782
  • 7,087
  • 14
  • 68
  • 143
  • 1
    It is forbiden for evident security reasons... – n00dl3 Oct 17 '16 at 15:00
  • 2
    Possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – n00dl3 Oct 17 '16 at 15:01
  • Possible duplicate of [Selecting an element in iFrame jQuery](http://stackoverflow.com/questions/6316979/selecting-an-element-in-iframe-jquery) – Neo Oct 17 '16 at 15:02
  • @n00dl3 But then if jquery `contents` can overrule that forbiddeness then what is it's advantage? – user31782 Oct 17 '16 at 15:06

0 Answers0