【问题标题】:Remove div and table from td element using jquery使用 jquery 从 td 元素中删除 div 和 table
【发布时间】:2014-01-05 14:15:25
【问题描述】:

我有一个名为“ahblog.htm”的文件,其中包含一个“td 元素”。我正在使用“jquery”来提取“td 元素”(内容 topContent topContentBox)并将其放入“div”中。我遇到的问题是从“td 元素”中删除“div”和“table”。

下面是我的php代码

<?php 
include( 'site/simple_html_dom.php'); 
$html=file_get_html( 'http://achievementhunter.com/blog/');
$html->save('site/ahblog.htm')                      
?>
<script type="text/javascript" src="site/jquery.js"></script>
<script type="text/javascript">
$('document').ready(function() {
$('#wrap').click(function (event)
{
event.preventDefault();
});
$('#wrap').load('site/ahblog.htm .content.topContent.topContentBox');
});
</script>

下面是'td元素'

<div id="wrap">
<td class="content topContent topContentBox" height="100%" width="100%" valign="top">
<div class="titleLine"> <----- I want to remove this one
<div style id="streamDivLeveljournal43125372">
<div style id="streamDivLeveljournal100703120097">
<div style id="streamDivLeveljournal823117600">
<div style id="streamDivLeveljournal43115856">
<div style id="streamDivLeveljournal100703110797">
<table width="100%">...</table> <----- I want to remove this one
</td>
</div>

我遇到的问题是删除该表,因为有多个表,并且因为它没有“ID”。如果有人能帮助我,我将不胜感激。

【问题讨论】:

  • 为什么不加个ID?
  • 你为什么不添加一个id ?试试$(#wrap table)

标签: javascript php jquery html css


【解决方案1】:
$(".content.topContent.topContentBox").find(".titleLine, table").remove(); 

应该这样做。

【讨论】:

  • 感谢您的回答。我还有一个障碍,那就是让它发挥作用,因为我尝试了一些东西,但似乎无法让它发挥作用。
  • 我会把它放在你的负载调用的回调函数中,比如$('#wrap').load('site/ahblog.htm .content.topContent.topContentBox', function() { //remove div and table here });
  • 什么是不工作的?如果有控制台错误,您能提供吗?
  • 我知道了Uncaught SyntaxError: Unexpected end of input
  • 那是语法的问题,看看你是不是漏掉了}),可能是我写在cmets上的代码,纯属伪代码。
【解决方案2】:

试试这个:

$('#wrap td').find('.titleLine').remove();
$('#wrap td').find('table').remove();

【讨论】:

  • 很高兴帮助你@Sabre
猜你喜欢
  • 1970-01-01
  • 2019-06-27
  • 2011-09-23
  • 2013-10-10
  • 1970-01-01
  • 1970-01-01
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多