본문 바로가기

제이쿼리

this와 $(this)의 차이점

this

javascript의 경우에는 이벤트가 발생한 태그 요소가 표시된다.

 

$(this)

제이쿼리의 경우에는 이벤트가 발생한 요소의 정보들이 Object로 표시된다.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<div id="div1" style="height: 100px; width: 300px; border: 1px solid black; background-color: yellow;"></div>

<div id="test1"></div>

<div id="test2"></div>

<script type="text/javascript">

$(document).ready(function() {
    $("#div1").click(function() {
        console.log(this);
        console.log("=================");

        console.log($(this));
        $("#test1").text($(this));
        $("#test2").text(this);
    })
});



</script>



</body>
</html>


참고

m.blog.naver.com/PostView.nhn?blogId=software705&logNo=220978986713&proxyReferer=https:%2F%2Fwww.google.com%2F

 

[Javascript] javascript this와 $(this)의 차이점

[ this와 $(this)의 차이점 ] 얼마전까지 스크립트를 코드를 자면서 this , $(this) 를 동일한 성격으로 생...

blog.naver.com

 

'제이쿼리' 카테고리의 다른 글

[제이쿼리] 형(이전) / 동생(다음) 요소 선택자  (0) 2020.10.04
인접 관계 선택자  (0) 2020.10.01
기본 선택자  (0) 2020.09.30
.wrap  (0) 2020.09.20
제이쿼리 커스텀 태그와 .data  (0) 2020.09.20