JQuery append() DIV HTML 不带
一直试图找到这个问题的答案,但似乎无法理解它:
var newLayout = '<div id="blog-left"></div>' ; // This creates the layout the content will be moved to
newLayout += '<div id="blog-right" class="nivoSlider"></div>' ;
newLayout += '<div style="clear:both;"></div>' ;
newLayout += '<div id="img-temp" style="display:none;"></div>' ;
$('.blog').append(newLayout); // Add the new layout
$('#blog-left').append( $('.blog p') ); // All <p>'s being added to the new layout
$('#blog-right').append( $('.blog img') ); // All <IMG>'s being added to the new layout
这工作得很好,但是我遇到的问题是而不是将
附加到
#blog-left
我想附加所有包含的 HTML
但减去 标签。因此,所有
HTML
都进入 #blog-left
,而 进入 #blog-right。
我尝试过使用 .html()
,它在一定程度上有效,但 #blog-left
& #blog-right
位于包含 div .blog
中。
我已经尝试了一些方法,但没有任何结果正确返回(如果有的话)。那么各位聪明人有使用 JQuery 的解决方案吗?
提前致谢。
萨姆·T。
Been trying to find an answer to this but can't seem to get my head around it:
var newLayout = '<div id="blog-left"></div>' ; // This creates the layout the content will be moved to
newLayout += '<div id="blog-right" class="nivoSlider"></div>' ;
newLayout += '<div style="clear:both;"></div>' ;
newLayout += '<div id="img-temp" style="display:none;"></div>' ;
$('.blog').append(newLayout); // Add the new layout
$('#blog-left').append( $('.blog p') ); // All <p>'s being added to the new layout
$('#blog-right').append( $('.blog img') ); // All <IMG>'s being added to the new layout
This work really well, however the problem I have is instead of appending the <p>
to #blog-left
I want to append all the contained HTML
but minus the <IMG>
tags. So all HTML
goes into #blog-left
and <IMG>
's go into #blog-right.
I've tried using .html()
which works to a point but the #blog-left
& #blog-right
are in the containing div .blog
.
I've tried a couple of things but nothing returns correctly if at all. So do any of you bright sparks have the solution using JQuery?
Thanks in advance.
Sam T.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会这样做:
I would do it like so:
尝试这个来过滤掉 img 标签。
jsfiddle 上的示例。
Try this to filter out img tags.
Example on jsfiddle.