How to select with a specific style attribute?
<div style="width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;">
I'm trying:
$("div[style='width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;']);
but nothing gets selected.
jQuery [attribute|=value] Selector The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us"). Tip: This selector is often used to handle language attributes.
Apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call. Here you can pass key as property and val as its value as described above.
jQuery uses CSS-style selectors to select parts, or elements, of an HTML page. It then lets you do something with the elements using jQuery methods, or functions. To use one of these selectors, type a dollar sign and parentheses after it: $() . This is shorthand for the jQuery() function.
You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");
Your example works for me, in Chrome at least, once I corrected the typo of the missing " at the end of the line.
$("div[style='width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;']");
See this demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With