我正在尝试获取我的 event.target('h6.class') 的 .div('.child#') 子项的文本内容,并使用此脚本替换我的其他标题('h1.replacHeader#')以下...
$('h6.HeaderToBeClicked').click(function(event) {
var $target = $(this);
$('.replaceHeader1').replaceWith("<h1 class='replaceHeader1'>" + $target.children(".child1").text() + "</h1>");
$('.replaceHeader2').replaceWith("<h1 class='replaceHeader2'>" + $target.children(".child2").text() + "</h1>");
});
});
HTML:
<div id="ReplaceTheseHeaders">
<h1 class='replaceHeader1'></h1>
<h1 class='replaceHeader2'></h1>
</div>
<div id="accordian" class="acc">
<?php $counter = 1; ?>
<?php foreach ($tmpl->vars as $var) { ?>
<h6 class="HeaderToBeClicked"><a href="#">
<div class="counter"><?php print $counter . "." ?></div>
<div class="child1"><?php print $var['title'];?></div>
<div class="child2"><?php print $var['name'];?></div>
</a></h6>
<?php $counter = $counter+1; ?>
<?php } ?>
</div>
我注意到 .text() 显然不适用于 event.target ... 那么我该如何实现呢?