채택완료

ajax 토글동작 문의

Copy
<span  id="history">【여기】</span>
<span  id="history_html"></span>

 

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
$("#history").click(function() {
$("#history_html").fadeToggle();
$("#history_html").html("<br><span style=color:blue>【 TEST 】 (클릭)</span><br>");
})

</script>

 

위 코드를 실행하면

【여기】를 클릭했을때 첫클릭에서는 【 TEST 】란 문구가 나왔다가 바로 사라져버립니다.

이후 부터는 제대로 동작을 하는데 왜그러는지 모르겠네요.

해결책좀 알려주세요. 

 

 

 

|

답변 1개

채택된 답변
+20 포인트

fadetoggle을 하셨고 #history_html은 현재 보여지고 있는 상태이기 때문이죠 단지 내용이 없을뿐

간단하게

Copy
<span  id="history_html" style="display: none"></span>

하시면 됩니다.

답변을 작성하려면 로그인이 필요합니다.