Dynamically create buttons with Jquery

前端 未结 4 1807
旧时难觅i
旧时难觅i 2020-12-14 03:41

I need to create 10 buttons dynamically with Jquery and set the text on them to be 1 -10, and add the same click event to all of them.

Should I be using dom create e

4条回答
  •  鱼传尺愫
    2020-12-14 04:05

    See this on how to create elements using jQuery What is the most efficient way to create HTML elements using jQuery?

    Also, once you have created the element, to attach events you'll need to use the Live() keyword.

    $("#btn1").live("click", function(){ 
    //Do work
     });
    

提交回复
热议问题