DEV/javascript

Javascript 자식의 Function를 참조하는 방법

석봉 2022. 10. 29. 15:00

작업을 하다보면 하위 자식 함수에 접근이 필요한 경우가 있다.

( 대표적으로 iframe을 사용하는 경우 )

 

다음과 같이 접근이 가능하다.

/**
 *  [자식 함수에 접근하는 방법]
 *  - 현재 document 하위(자식) sampleEle 내부에 있는 functionName이라는 함수에 접근한다고 가정하자.
 */
document.getElementById("sampleEle").contentWindow.functionName(parameter);

 

jQuery 방식은 다음과 같이 사용

$('#sampleEle').get(0).contentWindow.functionName();

 


비슷한...?

https://seokbong.tistory.com/98

 

Javascript 자식의 element를 참조하는 방법 (가져오는 방법)

작업을 하다보면 하위 자식 요소에 접근이 필요한 경우가 있다. ( 대표적으로 iframe을 사용하는 경우 ) 다음과 같이 접근이 가능하다. /** * [자식 요소에 접근하는 방법] * - 현재 document에서 하위

seokbong.tistory.com

반대의...?

https://seokbong.tistory.com/94

 

jQuery 부모의 function을 사용하는 방법

이번 프로젝트에서 ifram 부모의 function을 참조할 일이 많았다. 자식의 js에서 부모 js의 function은 아주 쉽게 참조 가능하다. parent.functionName(); await parent.functionName(); // async - await를 사용..

seokbong.tistory.com