Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,622
    Thanks
    6
    Thanked 1,001 Times in 974 Posts

    jQuery CSS attribute selectors

    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/att...attributevalue) but somehow it doesn’t. Is the “style” attribute a special case or what?

    My code is simple:
    Code:
    $('img[style*=left]').addClass('left');


    Edit:
    Problem solved with a workaround:
    Code:
    $("img").each(function() {
    	if($(this).css('float')=='left') {
    			$(this).addClass('left');
    	}
    	else if($(this).css('float')=='right') {
    			$(this).addClass('right');
    	}
    });
    Last edited by VIPStephan; 01-29-2009 at 05:28 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •