DEV/javascript
jQuery 부모의 element를 참조하는 방법 (가져오는 방법)
석봉
2022. 7. 30. 21:48
작업을 하다 보면 iframe을 쓰거나 부모의 element 요소를 참조하는 경우가 있다.
자식 페이지에서 부모의 element를 참조할 때는 다음과 같이 사용하자.
부모의 element의 값을(value) 가져오는 경우
$('#id', parent.document).val();
$('.class', parent.document).val();
$('button', parent.document).val();
...
일반적으로 jQuery 선택자를 이용하는 법을 사용하고 parent.document 를 추가로 넣어주면 된다.
.val(), .text(), .html() 등 일반적인 jquery 함수를 사용할 수 있다.
https://seokbong.tistory.com/94
jQuery 부모의 function을 사용하는 방법
이번 프로젝트에서 ifram 부모의 function을 참조할 일이 많았다. 자식의 js에서 부모 js의 function은 아주 쉽게 참조 가능하다. parent.functionName(); await parent.functionName(); // async - await를 사용..
seokbong.tistory.com