Javascript, CSS: Get element by style attribute

后端 未结 5 1689
逝去的感伤
逝去的感伤 2020-12-03 17:38

I\'d like to:

  1. Find a style attribute for all elements in the page (for instance: all elements that have color:#333;)
  2. Change this attribut
5条回答
  •  甜味超标
    2020-12-03 18:30

    It's definitely more simple if you use jquery. In any case, the best would be to use classes and use the filter jquery method to get the objects you want.

    But if you really want to get them you can do something like:

    $(function () {
        $('p').filter(function () {
            return $(this).css('color') == '#333';
        }).css('color', '#444');
    });
    

    The above script get the elements with the desired css attribute and set a new css attribute (color #444).

提交回复
热议问题