jQuery add next to (add after)

前端 未结 5 1946
刺人心
刺人心 2021-01-03 17:59

HTML is
ref

I need to get
reftext

How can i do this? $(\'a\').append(\'text\')<

相关标签:
5条回答
  • 2021-01-03 18:15

    use .insertAfter() or .after()

    0 讨论(0)
  • 2021-01-03 18:18

    Use after or insertAfter:

    $('a').after('text');
    $('text').insertAfter('a');
    
    0 讨论(0)
  • 2021-01-03 18:19

    You can do something like this:

    $('').insertAfter('class name or content string') ;
    
    0 讨论(0)
  • 2021-01-03 18:24

    Using the following HTML:

    <div class="container">
      <h2>Greetings</h2>
      <div class="inner">Hello</div>
      <div class="inner">Goodbye</div>
    </div>
    

    Content can be created and then inserted after several elements at once:

    $('.inner').after('<p>Test</p>');
    

    Each inner element gets this new content:

    <div class="container">
      <h2>Greetings</h2>
      <div class="inner">Hello</div>
      <p>Test</p>
      <div class="inner">Goodbye</div>
      <p>Test</p>
    </div>
    

    An element in the DOM can also be selected and inserted after another element:

    $('.container').after($('h2'));
    

    If an element selected this way is inserted elsewhere, it will be moved rather than cloned:

    <div class="container">
      <div class="inner">Hello</div>
      <div class="inner">Goodbye</div>
    </div>
    <h2>Greetings</h2>
    
    0 讨论(0)
  • 2021-01-03 18:40
    $('a').after("text");
    
    0 讨论(0)
提交回复
热议问题