2011-07-27 5 views

답변

5

가장 쉬운 방법. jQuery를 사용

var targetElem = document.getElementById('myid'); 

targetElem.innerHTML = '<strike>' + targetElem.innerHTML + '</strike>'; 

는,이 작업은 약간 더 단순하게 .contents() + .wrapAll()를 사용하여 :처럼이 볼 수 있었다

targetElem.style.textDecoration = 'line-through'; 
:

$('#myid').contents().wrapAll('<strike/>'); 

또 다른 대안은, CSS를 사용하는 것도 아이디어가 될 수있다

또는 브라우저 간 호환을 위해 jQuery를 다시 사용 :

$('#myid').css('text-decoration', 'line-through'); 
+0

나는 마지막 옵션이 최고라고 생각한다. – Ibu

+0

CSS가 마지막 대안인가? – Felix

+0

@ Felix : 나는 이런 뜻이 아니 었습니다. 제가 말하고자하는 것은 마지막으로 "작은 목록에"있습니다. – jAndy

2

CSS :

.strike{ 
    text-decoration:line-through; 
} 

jQuery를 : 그냥 HTML 콘텐츠 자체를 조작 할 수 있어야 자바 스크립트 바닐라를 사용하여 갈

jQuery("#yourid").addClass("strike"); 
0

은 단순히 당신이 jQuery를 사용하는 경우이 간단 할 것 yourID

의 장소에 ID를 넣어.

$("#yourID").css("textDecoration", "line-through"); 

JQuery를 사용하지 않는 경우.

var element = document.getElementById('yourID'); 
element.style.textDecoration = 'line-through'; 

하지만 모든 브라우저에서 작동하는지 잘 모르겠습니다.

3

document.getElementById('foo').style.textDecoration ='line-through'; 
관련 문제