我想修改父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