【问题标题】:remove div from inside embedded object with jQuery使用 jQuery 从嵌入对象中删除 div
【发布时间】:2012-11-20 19:04:32
【问题描述】:

我在我的网站上嵌入了一个对象,并想从中删除一个 div。那可能吗? 我想用 jQuery 删除对象标签内具有特定 id 的 div。我尝试了下面的 jQuery,但它没有选择嵌入对象内的 div。

$("div").filter(function(){
console.log(this.id); // i don't see any of the id's from the div's inside my object 
});

编辑:

<object data=http://www.msn.com width='100%' height='100%'>
<embed src=http://www.msn.com width='100%' height='100%'>
</embed> Error: Embedded data could not be displayed. </object>

我需要删除我网站上嵌入对象中的一个 div。

请帮忙。

谢谢

【问题讨论】:

  • 请改用this.id。您正在创建一个没有 id 属性的 jQuery 对象。
  • 使用this.id$(this).attr('id')
  • @undefined 而不是 $(this).id?
  • 我仍然没有看到对象内部的 div
  • 嗯..所以您正在将一个页面嵌入到您的页面中..并想从那里删除一个 div?

标签: jquery object select tags


【解决方案1】:
$(this).attr('id')  // $(this)  is jQuery Object

this.id //  this is DOM Object

/

$("div").filter(function(){
       return this.id != 'div1' && this.id != 'div2' ;
}).css('backgroundColor' , 'orange')​

Check Fiddle

【讨论】:

  • 请重新阅读我的问题,我进行了编辑以更好地澄清。谢谢
  • 虽然 $(this).prop('id') 可能与 this.id 更一致,因为 id 是元素的属性 - 请注意属性 . 表示法
  • @wirey ..感谢您指出...我觉得 id 不是元素的属性,而是属性...。如果您告诉我 attr() vs .prop() ,我认为静态属性应该不是问题..
猜你喜欢
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多