How do you select elements based on their style?(你如何根据风格选择元素?)

本文介绍了你如何根据风格选择元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jQuery,您将如何找到具有特定样式的元素(例如:float:left),无论它是内联样式还是在 CSS 文件中定义的样式?

Using jQuery, how would you find elements which have a particular style (eg: float: left), regardless of whether it's an inline style or one defined in a CSS file?

推荐答案

使用过滤功能:

$('*').filter(function() {
     return $(this).css('float') == 'left';
});

用适合您情况的选择器替换*".

Replace '*' with the appropriate selectors for your case.

这篇关于你如何根据风格选择元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!