用jquery更改div文本

时间:2010-10-11 01:54:38

标签: javascript jquery

当我点击div时,我想将其中的文本更改为New Text

我如何用jquery

来做到这一点
$('#mydiv').????

3 个答案:

答案 0 :(得分:3)

$('#mydiv').click(function(){
    this.innerHTML = "New Text";
});

crazy demo

如果你有东西需要链接,你可以这样做,

$('#mydiv').click(function() {
    $(this).html("New Text") // can include html tags, use .text() for text only.
        .animate({marginLeft: '+=10'}); // chain an animation...
});

crazy demo

答案 1 :(得分:2)

绑定一个事件并处理它:

$('#mydiv').click(function() {
    $(this).html("New Text");
});

或使用bind

$('#mydiv').bind("click", function() {
    $(this).html("New Text");
});

live

$('#mydiv').live("click", function() {
    $(this).html("New Text");
});

<强>参考

答案 2 :(得分:1)

$('#mydiv').click(function() {
    $(this).html("New Text");
});