我想知道如何获得一个元素,其中类名不等于传入的值。例如:
$(document).ready(function () {
$(document).on('change', '#allRolesDD', function () {
var toShow = document.getElementsByClassName($(this).val());
//Below line is the one where I want to get the value where the class name is not equal to the value
var toHide = document.getElementsByClassName(!$(this).val());
alert($(toHide).html());
toHide.attr('hidden', true);
toShow.show();
});
});
答案 0 :(得分:2)
$('selector:not(.hateThisClass)')
您还可以使用.not()
"从匹配元素集中删除元素。"
$('selector').not('.hateThisClass')
完整代码:
$(document).on('change', '#allRolesDD', function () {
var toShow = '.' + $(this).val();
$(toShow).show();
$(':not(' + toShow + ')').hide(); // Assumed the elements need to hide, not just adding an attribute
});
答案 1 :(得分:0)
答案 2 :(得分:0)
不要混淆纯JavaScript和jQuery,使用:not
选择器过滤掉这样:
<Path Grid.Column="0" Width="16" Height="16" Fill="{DynamicResource WindowForegroundBrush}" Stretch="Uniform">
<Path.Data>
<GeometryGroup >
<Geometry>some geometry data1</Geometry>
<Geometry>some geometry data2</Geometry>
<Geometry>some geometry data3</Geometry>
</GeometryGroup>
</Path.Data>
</Path>