반응형
Description (설명)
jQUERY.text( textValue )
Example (예시)
// span 태그의 textNode 값 변경하기
<span id="color">yellow</span>
<button type="button" onclick="change_color('red')>빨강으로 변경</button>
<button type="button" onclick="change_color('yellow')>노랑으로 변경</button>
<script>
function change_color(color){
$("span#color").text(color);
}
</script>
// 특정 조건의 태그들 일괄 변경하기
<div id="groups">
<span class="group1">OK</span>
<span class="group1">NO</span>
<span class="group2">NO</span>
<span class="group1">NO</span>
<span class="group3">OK</span>
</div>
<button type="button" onclick="only_group1()">group1만 OK</button>
<script>
function only_group1(){
$("div#groups span").each(function(i, v){
if($(v).hasClass('group1')){
$(v).text('OK');
}else{
$(v).text('NO');
}
});
}
</script>
반응형