jQuery: Add element after another element

社会主义新天地 提交于 2019-11-26 08:48:33

问题


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 have:

<input type=\"text\" id=\"bla\" />

and I want to change that into:

<input type=\"text\" id=\"bla\" /><div id=\"space\"></div>

回答1:


try using the after() method:

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

Documentation




回答2:


try

.insertAfter()

here

$(content).insertAfter('#bla');



回答3:


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.




回答4:


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>


来源:https://stackoverflow.com/questions/2244605/jquery-add-element-after-another-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!