How to add text to an existing div with jquery

前端 未结 6 439
礼貌的吻别
礼貌的吻别 2020-12-08 00:27

I want to add text to an existing div, when I click the Button with the id #add. But this is not working.

Here my code:

6条回答
  •  臣服心动
    2020-12-08 00:57

    Running example:

    //If you want add the element before the actual content, use before()
    $(function () {
      $('#AddBefore').click(function () {
        $('#Content').before('

    Text before the button

    '); }); }); //If you want add the element after the actual content, use after() $(function () { $('#AddAfter').click(function () { $('#Content').after('

    Text after the button

    '); }); });
    
    
    

提交回复
热议问题