How to remove a single class when iterating over a node list in Dojo?
I want to remove one of two classes BUT leave any other class(es) in place.
For example, I start with a node like this:
<td class="aaa ddd">
I want to remove only aaa
. I also want to use a selector that selects many nodes at once.
For example:
dojo.query('#foo td').removeClass(['aaa','bbb']);
The above piece of code removes all classes in 开发者_运维技巧the TD. I just want to remove 'aaa' or 'bbb'.
Thank you.
What you have posted seems to work to me. For example:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"></script>
<script>
dojo.addOnLoad(function()
{
dojo.query('#foo td').removeClass(['aaa', 'bbb']);
});
</script>
<style type="text/css">
.aaa
{
color: red;
}
.bbb
{
background-color: yellow;
}
.ccc
{
text-decoration: underline;
}
.ddd
{
background-color: gray;
}
</style>
<table id="foo">
<tr>
<td class="aaa bbb ccc ddd">A</td>
</tr>
<tr>
<td class="aaa bbb ccc">B</td>
</tr>
<tr>
<td class="aaa bbb ccc ddd">C</td>
</tr>
<tr>
<td class="aaa bbb ccc">D</td>
</tr>
<tr>
<td class="aaa bbb ccc ddd">E</td>
</tr>
</table>
精彩评论