2016년 10월 4일 화요일

[Ajax강의,jQuery강의,자바강의★탑크리에듀]jquery 강좌 문서 객체의 내부에 내용물을 추가하고 싶을 때 $(selector).html, $(selector).text

문서 객체의 내부에 내용물을 추가하고 싶을 때

$(selector).html(value);      $(selector).text(value);
$(selector).html(function(index, html){ }); 
$(selector).text(function(index, text){ });

<html><head><meta charset="utf-8"/>
<script src="/ajaxjquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("div").html(function (index) {
//html출력이므로 <h3>태그는 안보임 
return "<h3>hello~ onjprogramming" + index + "</h3>";
});
alert(1);
$(document).ready(function() {
$("div").text("<h2>text output</h2>");//text형태로 <h2>도 출력됨
});
});
</script><body>    
<div></div>
<div></div>
</body></html>
 
 
 
j5.png

j6.png

댓글 없음:

댓글 쓰기