How to create div with class

后端 未结 5 451
感情败类
感情败类 2021-02-02 07:15

I\'m trying to create a div and give him a class but it doesn\'t work. Could anybody help me?

$(document).ready(function() {
$(\'input[type=checkbox]\').each(fun         


        
相关标签:
5条回答
  • 2021-02-02 07:29
    $(document).ready(function() {
    $('input[type=checkbox]').each(function() {
        $(this).after($('<div />', {
            class: 'test',
            text: "a div",
            click: function(e){
                e.preventDefault();
                alert("test")
            }}));
        });
    });
    

    http://jsfiddle.net/yF9pA/1/

    0 讨论(0)
  • 2021-02-02 07:32

    try class instead of className

    0 讨论(0)
  • 2021-02-02 07:35
    $('input[type=checkbox]').each(function() {
    
    $(this).after('<div></div>').addClass('test')
      .filter('div').html('a div')
    .click(function() {
      alert('Handler for .click() called.');
    }).end()
    .appendTo('this');
    
    });
    

    Should work :)

    0 讨论(0)
  • 2021-02-02 07:47

    use "class" instead of className

    $('<div />', {
            "class": 'test',
            text: "a div",
            click: function(e){
                e.preventDefault();
                alert("test")
            }})
    
    0 讨论(0)
  • 2021-02-02 07:51
     $('<div>', { 'class': 'your_class' })
                     .load('HTML Structure', CallBackFunction())
                     .appendTo(document.body);
    
    0 讨论(0)
提交回复
热议问题