VIPStephan
01-28-2009, 06:46 PM
I want to get elements with the attribute/value combination of style="float: left;" and add a class to them. Is this even possible? Because all I’ve tried so far hasn’t led to any result.
I’ve looked at http://docs.jquery.com/Selectors and to me it seems that actually [attribute*=value] should do the trick (http://docs.jquery.com/Selectors/attributeContains#attributevalue) but somehow it doesn’t. Is the “style” attribute a special case or what?
My code is simple:
$('img[style*=left]').addClass('left');
:confused:
Problem solved with a workaround:
$("img").each(function() {
if($(this).css('float')=='left') {
$(this).addClass('left');
}
else if($(this).css('float')=='right') {
$(this).addClass('right');
}
});
I’ve looked at http://docs.jquery.com/Selectors and to me it seems that actually [attribute*=value] should do the trick (http://docs.jquery.com/Selectors/attributeContains#attributevalue) but somehow it doesn’t. Is the “style” attribute a special case or what?
My code is simple:
$('img[style*=left]').addClass('left');
:confused:
Problem solved with a workaround:
$("img").each(function() {
if($(this).css('float')=='left') {
$(this).addClass('left');
}
else if($(this).css('float')=='right') {
$(this).addClass('right');
}
});