Using jQuery, how can I say ‘Does a child of #parent have the stlye=”width”‘.
I know the beginning…
jQuery('#parent').children();
But I dont know how to write has style ‘width’.
EDIT
In the html the div says style=”width=xxx”. I want to find the first occurrence of that width and add a margin: 0 auto; to that div. Its for centering videos.
Some of the divs that say style=”width” are 3 levels nested from the top. That still should work with .children() right?
For some reason, i cant get any of the below codes to work…
You need to use an “attribute contains” selector:
That will give you the children of
#parentthat have the stringwidth:in theirstyleattribute.Example: http://jsfiddle.net/ambiguous/vpdGa/1/
If you need to worry about
border-widthand similar CSS properties, then you could add your regular expression selector:And then search thusly:
Don’t forget the extra backslash to get past the string literal’s backslash interpretation.
And an example of this approach: http://jsfiddle.net/ambiguous/vpdGa/4/