如何在div内容上添加段落 [英] how to add paragraph on top of div content

查看:967
本文介绍了如何在div内容上添加段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加多个段落标签,新标签位于div容器的顶部。

How can I add multiple paragraph tag, newly tag on top within div container.

<div id="pcontainer">
  <p>recently added on top every time on click event recently added paragarph on top</p>
  <p>added before recent</p>
</div>

我正在使用附加功能,但每次点击按钮添加到底部时,我需要添加到顶部所有段落请帮忙。

I am using append but every time I click button it add to bottom I need it to added on top of all paragraph please help.

推荐答案

您可以使用 prepend 在容器顶部添加段落:

You may use prepend to add the paragraph at the top of the container:

// HTML: <div><p>Lorem ipsum</p></div>
$('div').prepend('<p>Bla bla bla');

更新:关于您关于如何淡出段落的评论 - 使用 fadeIn

Update: Regarding your comment about how to fade in the paragraph - use fadeIn:

$("#pcontainer").prepend($('<p>This paragraph was added by jQuery.</p>').fadeIn('slow'));

工作演示: http://jsbin.com/uneso

这篇关于如何在div内容上添加段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆