Can you use jquery to add comments dynamically to code?

前端 未结 9 1460
无人共我
无人共我 2021-01-18 05:20

I tried:


but it didn

相关标签:
9条回答
  • 2021-01-18 06:07
    $("<!--your comment text here -->").insertAfter(selector);
    

    or

    $(selector).after("<!--your comment text here -->");
    

    live demo

    0 讨论(0)
  • 2021-01-18 06:08

    Some options:

    $('.mycurrentclass').remove(); 
    
    $('.mycurrentclass').detach();// see below for possible use
    
    $('.mycurrentclass').css({display:'none'});
    
    $('.mycurrentclass').hide(); 
    
    $('.mycurrentclass').toggleClass('myhiddenclass');
    
    $('.mycurrentclass').addClass("myhiddenclass");
    
    $("myselector").toggle(
      function () {
        $(this).addClass("myhiddenclass");
      },
      function () {
        $(this).removeClass("myhiddenclass");
      }
    );
    
    // programtic like you seem to want:(first part puts it back, else detaches it)
    var p;
    if ( p ) 
    {
      p.appendTo("mywheretoappenditselector");
      p = null;
    } 
    else 
    {
      p = $("myselector").detach();
    };
    
    0 讨论(0)
  • 2021-01-18 06:08

    I think you would need prepend and append to do it the way you are thinking. Not sure if it would actually make things disappear though.

    If you want something to not be visible, your best bet would be to use hide().

    0 讨论(0)
提交回复
热议问题