1

I want to access a div element inside a iframe. This iframe load from a different domain.

below code I tried:

$('iframe').contents().find(".questions").width()
CMartins
  • 3,247
  • 5
  • 38
  • 53
  • 5
    As long as [CORS](https://developer.mozilla.org/de/docs/Web/HTTP/CORS) is not enabled for both domains you cannot. – empiric Aug 20 '19 at 06:25
  • What do you expect with width()? Can you try hide() or something similar. – tom Aug 20 '19 at 06:26
  • 4
    Possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](https://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – peeebeee Aug 20 '19 at 06:35
  • @empiric I have loaded this iframe in vue frontend and load jquery based domain into this iframe.When I used above code I could not able to take the width of the element. – Supun Premarathna Aug 20 '19 at 12:51
  • @kmgt No. I want to get width of this div to calculation. Any way I want to get element width only – Supun Premarathna Aug 20 '19 at 12:53

1 Answers1

0

Are there multiple .questions class?

To get witdth of first one, try this:

$('iframe').contents().find(".questions:first").width();
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33