2013-08-19 3 views
0

jQuery .html()을 사용하지만 다른 HTML 요소를 제거하지 않고 요소를 추가 할 수 있습니까? 그래서기존 콘텐츠를 삭제하지 않고 요소 추가

내 코드 조회 : 나는 JQuery와 함께이 시도

<div id="contentboxes"> 
    <div class="con1">content 1</div> 
    <div class="con1">content 2</div> 
</div> 

:

$('#contentboxes').html('<div class="con3">Content 3</div>'); 

그러나이 명령은, 내 다른 2 상자를 제거는 다른 상자를 제거하기없이 추가 할 수 있습니다?

+2

APPEND() 앞에 추가() 이전에 insertbefore 후() insertafter 속성()()() ..... JQuery와 테이블에 새로운 요소를 삽입 [ – adeneo

+0

의 중복 가능성 셀을 지우지 않고 다른 요소] (http://stackoverflow.com/questions/17536561/jquery-insert-new-element-into-table-cell-without-erasing-other-elements) –

+0

나는 항상 살펴 보길 권합니다. 설명서는 http://api.jquery.com/category/manipulation/에서 확인할 수 있습니다. –

답변

5

.html() 대신 .append()을 사용하십시오.

+1

또는 심지어 [prepend()] – Alvaro

+1

또한 .prepend(), .after() 및 .before() 유용 할 수 있습니다 – cernunnos

+0

.prepend() 그게 내가 뭐야? 필요, 고마워 :) – user2496077

관련 문제