jQuery find by inline css attribute

后端 未结 8 1863
深忆病人
深忆病人 2020-12-06 00:14

I need to find an element based on a specific css attribute. The css is applied inline and I can not use a class. Is there anyway to achieve this i

8条回答
  •  离开以前
    2020-12-06 00:34

    Yes, I think the fastest and easiest way to achieve the desired results would be to target styles with a property class selector.

    Like stated before:

    $('div.yourClass[style*="background-color:Blue"]).css('color', 'White');
    

    That way we target all divs with same class that have blue background and tell them all to have white color text. Of course instead of .css we can use anything here, .animate and tell all blues to be animated etc. This helped me a lot with DB relations and people setting up strange things in DB.

    I used to be less generic, and target strings with :contains... but then somebody goes to the base, and changes texts and labels, and bye bye code ;)

    Hope it helps.

提交回复
热议问题