简体   繁体   English

jQuery删除CSS样式?

[英]does jquery remove css style?

I'm tying to troubleshoot a problem with my css. 我想解决CSS的问题。 I have the following div tag: 我有以下div标签:

<div class="span1" id="progress-indicator" style="text-align:left; border:2px solid #000;">&nbsp;</div>

Later on in my script section of the code, I do something like this: 稍后,在代码的脚本部分中,我将执行以下操作:

 $('#progress-indicator').html("saving changes....");

When you use the html() method, is it only changing the space between the opening / closing div tags or does it change the attributes of the div tag? 当您使用html()方法时,它是仅更改打开/关闭div标签之间的空间还是更改div标签的属性? I'm asking because once this jquery is called, the size of the div seems bigger than a span1 div should be. 我问是因为一旦调用了该jquery,div的大小似乎就会比span1 div更大。

Thanks. 谢谢。

The jQuery documentation only mentions that the content is affected: http://api.jquery.com/html/ jQuery文档仅提及内容受到影响: http : //api.jquery.com/html/

I quote: "Description: Set the HTML contents of each element in the set of matched elements." 我引用:“描述:设置匹配元素集中每个元素的HTML内容。”

An example of the jquery documentation: jQuery文档的示例:

$('div.demo-container')
    .html('<p>All new content. <em>You bet!</em></p>');

That line of code will replace everything inside : 该行代码将替换其中的所有内容:

<div class="demo-container">
  <p>All new content. <em>You bet!</em></p>
</div>

I set up an example: http://jsfiddle.net/caZtd/ 我设置了一个示例: http : //jsfiddle.net/caZtd/

Now if you click the progress-indicator div and you inspect the element before and after clicking (with firebug in firefox of the chrome developer tools), you will see that there is no difference in the html markup whatsoever. 现在,如果您单击进度指示器div,并在单击前后检查元素(使用chrome开发人员工具的firefox中的firebug),您将发现html标记没有任何区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM