0

当父母被改变时,有没有办法不影响父母内部的孩子?

<p>old text <a class="mylink">old link text</a></p>

$("a.mylink").click(function() {
        $(this).parent().text("new text for p");
        $(this).text("new link text for a");
    });
});

以上似乎完全摆脱了链接文本。我基本上希望能够在点击发生时更改这两个文本。

谢谢你。

4

2 回答 2

2

不是 JQuery 解决方案,但这有效:

$("a.mylink").click(function() {
    $(this)[0].previousSibling.nodeValue = "new text for p";
    $(this).text("new link text for a");
});
于 2010-03-13T18:35:52.237 回答
1

你可以试试这个技巧。有用

 $("a.mylink").click(function() {
       $(this).parent().html("new text for p" + $(this).text("new link text for a").html());
   });
于 2012-08-23T10:00:09.483 回答