Can you target classes with jquery?
What I want to do is $('.开发者_开发问答class.img').css('cellpadding', variable);
It doesn't seem to be working. I tried googling to no avail. Any help would be appreciated. I'm trying to apply it to an image inside the element with the given class.
CSS applies the styling properties inline as in style="..."
and does not modify the .class itself.
$('.class').css
does not do anything.
$('.class').css('color','red')
writes a color style
$('.class').css('color')
reads the color style
So to target your img
elements within an element with class "cellBox":
var borderx = "1px solid red";
$('.cellbox img').css('border',borderx);
(That sets border
, but you can set padding
the same way.)
Check working example at http://jsfiddle.net/SBjfp/2/
(Note that the jQuery documentation says that shorthand properties like padding
or border
are not supported; this mostly applies to getting the properties; setting [as above] usually works because it's supported by the underlying browser's implementation.)
The jQuery selector engine works perfectly well with class selectors.
The only thing clearly wrong with this (there might be other things, but you haven't provided any context (such as what the document looks like or when the statement is run)) is that css
is a function, and you aren't calling it (i.e. css('foo')
).
精彩评论