Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: select style attribute?

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.

like image 685
mmierins Avatar asked Nov 27 '10 12:11

mmierins


People also ask

What is attribute selector jQuery?

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.

How can give multiple CSS properties in jQuery?

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.

Can you use CSS selectors in jQuery for selecting elements?

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.

How do I retrieve the properties of a CSS element?

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");


1 Answers

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.

like image 119
Orbling Avatar answered Sep 18 '22 17:09

Orbling