「jQuery」append()で複数のタグを追加するサンプル

2021年2月19日

書式
$変数名 = $(“<input>",{属性1,属性2});
使用例
1.htmlコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div class="cft">
<p> study skill and become strong,Do you understand? </p>
</div>
<button type="button" id="regTest">登録</button>
<div class="cft"> <p> study skill and become strong,Do you understand? </p> </div> <button type="button" id="regTest">登録</button>
<div class="cft">
   <p> study skill and become strong,Do you understand? </p>
</div>
<button type="button" id="regTest">登録</button>

2.JavaScriptコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$("regTest").click(functon(){
var $inputtag =$("<input>",{
"type" : "radio",
"name" : "username",
"id" : "id007",
"value" : "study skill in arkgame"
});
$(".cft").append($inputtag);
});
$("regTest").click(functon(){ var $inputtag =$("<input>",{ "type" : "radio", "name" : "username", "id" : "id007", "value" : "study skill in arkgame" }); $(".cft").append($inputtag); });
$("regTest").click(functon(){
      var $inputtag =$("<input>",{
             "type" : "radio",
             "name" : "username",
              "id"  : "id007",
              "value" : "study skill in arkgame"
         });
         $(".cft").append($inputtag);
});

 

jQuery

Posted by arkgame