使用jQuery将div内每个表tr和td元素的样式属性设置为none [英] Setting style attribute to none for every table tr and td elements inside a div using jquery

查看:388
本文介绍了使用jQuery将div内每个表tr和td元素的样式属性设置为none的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ID为testdiv的div.在div内部,我有一个没有id或class的表.我想将div中所有表tr和td元素的style属性设置为none. 如何使用jquery代码完成此操作.一些示例代码将不胜感激

I have a div with id testdiv. Inside the div i have a table with no id or class . I would like to set the style attribute of all table tr and td elements inside the div to none. How can this be done using jquery code. Some example code would be really appreciated

请帮助. 谢谢

推荐答案

您可以使用 .removeAttr() ,像这样:

You can use .removeAttr(), like this:

$("#testdiv").find("table, tr, td").removeAttr("style");

请注意,尽管这只会删除内联样式,但样式表中定义的内容仍然适用.

Note though this just removes inline styles, whatever's defined in your stylesheets will still apply.

从更一般的角度来看,不需要ID来选择元素,您只需使用像我在上面的 .find() 调用中一样的元素选择器查找该<div id="testdiv">的后代的所有<table><tr><td>元素.

From a more general standpoint, an ID is never needed to select an element, you can just use an element selector like I have in the .find() call above, so for example this code looks for all <table>, <tr>, and <td> elements that are descendants of that <div id="testdiv">.

这篇关于使用jQuery将div内每个表tr和td元素的样式属性设置为none的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆