我想修改父div的文本而不更改子div內容。如何更改父div的內容從子div?
我已經
<div id='testDiv'>
this is the test parent div
<div id='child1'>
lots of contents and child div
...................
</div>
more div/child div and contents...
</div>
在我的jQuery
$('child1 div a').click(function(){
$('#testDiv').text('new text'); //this will remove the child1 div and all the contents inside testDiv
//I want to replace 'this is the test parent div' text to 'newt text'
})
是否有反正來完成這件事?非常感謝!
'{id:「test」}'是一個壞主意。改用類。 – VisioN
@VisioN - 這只是一個展示如何訪問包裝範圍的基本方法,並且與類/標識符的討論無關? – adeneo
這段代碼並不是完全透明的,當然,明確指出需要改變的那段文本會更有意義嗎?畢竟,如果它是可識別的,它必須有一些語義含義,所以標記應該反映這一點。 – Nick