How can I add an element after another element?

前端 未结 4 1173
渐次进展
渐次进展 2020-11-28 20:42

I have a certain textbox and I want to add a div after it. I\'ve tried the .append() function, but that only adds the div in the element.

For example, I

相关标签:
4条回答
  • 2020-11-28 21:01

    try

    .insertAfter()
    

    here

    $(content).insertAfter('#bla');
    
    0 讨论(0)
  • 2020-11-28 21:09

    First of all, input element shouldn't have a closing tag (from http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT : End tag: forbidden ).

    Second thing, you need the after(), not append() function.

    0 讨论(0)
  • 2020-11-28 21:11

    try using the after() method:

    $('#bla').after('<div id="space"></div>');
    

    Documentation

    0 讨论(0)
  • 2020-11-28 21:15

    Solved jQuery: Add element after another element

    <script>
    $( "p" ).append( "<strong>Hello</strong>" );
    </script>
    

    OR

    <script type="text/javascript"> 
    jQuery(document).ready(function(){
    jQuery ( ".sidebar_cart" ) .append( "<a href='http://#'>Continue Shopping</a>" );
    });
    </script>
    
    0 讨论(0)
提交回复
热议问题