Javascript jquery获取剥离样式属性的元素的HTML
是否可以获取元素的原始HTML,或者是否可以获取不带“style”属性的HTML?考虑下面的例子,Javascript jquery获取剥离样式属性的元素的HTML,javascript,jquery,html,css,jquery-animate,Javascript,Jquery,Html,Css,Jquery Animate,是否可以获取元素的原始HTML,或者是否可以获取不带“style”属性的HTML?考虑下面的例子, <div class="outer"> <div class="inner"> some text </div> </div> 当我使用console.log($('.outer').HTML()获取“outer”元素的HTML时,我得到以下信息 <div class="inner" style="margin-to
<div class="outer">
<div class="inner">
some text
</div>
</div>
当我使用console.log($('.outer').HTML()获取“outer”元素的HTML时代码>,我得到以下信息
<div class="inner" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
some text
</div>
一些文本
但是,我实际上只需要这个
<div class="inner">
some text
</div>
一些文本
获得输出的最简单方法是什么??在应用animate()或css()之前,我不需要创建元素的备份
谢谢。如果您想完全删除样式属性(并且不想再删除),请使用以下代码:
/* Working code */
$(".outer").find(".inner").removeAttr('style').end().html();
/* Explanation of working code */
$(".outer") // Get the outer element
.find(".inner") // Find the inner div
.removeAttr('style') // Remove the attribute from the inner div
.end() // Return to the outer div
.html(); // Get outer div's HTML
给你
jQuery文档:
如果要完全删除样式属性(并且不想将其重新删除),请使用以下代码:
/* Working code */
$(".outer").find(".inner").removeAttr('style').end().html();
/* Explanation of working code */
$(".outer") // Get the outer element
.find(".inner") // Find the inner div
.removeAttr('style') // Remove the attribute from the inner div
.end() // Return to the outer div
.html(); // Get outer div's HTML
给你
jQuery文档:
“当我得到“外部”元素的HTML时”。你怎么知道的?您可以发布您正在使用的代码吗?请尝试$('.inner')。removeAttr(“style”)代码>在获取“外部”元素的HTML时删除“样式”。你怎么知道的?您可以发布您正在使用的代码吗?请尝试$('.inner')。removeAttr(“style”)
以删除样式