1

I am using a grid layout (Bootstrapper) to display images of a certain width in rows.

<li class="span4"><div id="id" class="thumbnail"><img src="**path**"><img></div></li>
<li class="span12"><div id="id-2" class="thumbnail"><img src="**path**"><img></div></li>
<li class="span3"><div id="id-3" class="thumbnail"><img src="**path**"><img></div></li>

I'd like to be able to make an image's width span all columns (class="span12") when a user clicks on the image and to revert the image back to the "hardcoded" class of the image when the user clicks on the image again.

if (current_span != 'span12') // If image is not already spanning all columns ("span12")
{
$(this).attr('class','span12'); // Add class to span all columns
}

Using the above JS, images are displaying with the correct width after one click.

However, on the second click I'd like to revert back to the "hard-coded" class since not all images have the same class (i.e., some belong to 'span3', others to 'span4' and other to 'span12'.

Is there a way to revert back to the "hardcoded" class from the HTML on the second click?

2 Answers 2

3

CSS classes will cascade, so the last one in the queue will overwrite any preceding ones. You should be able to simply toggle the "span12" class on/off with jQuery:

$(this).toggleClass('span12');
Sign up to request clarification or add additional context in comments.

4 Comments

I appreciate your answer, however toggleClass is not producing an effect on the image width (span). I do not want to remove the class, I just want to be able to revert back to the "original" hardcoded class from the HTML.
have you checked if the styles of span12 are active afterwards? you could try using column-span:all !important;
I get the feeling that changing the class to one of the boot-strap classes is not the way to go, you should create a new CSS class li.expanded with img.expanded with specific rules and then toggle that class, that way you won't be messing around with the classes that are fundamental to the pages layout.
I'll create a new CSS class and toggle it. Good idea.
2

are you requiring a class for that? if the previous answer does not work you can try

$(this).css('column-span','all');

and to remove it either if you have no locale style attribute

$(this).removeAttr( 'style' );

or otherwise

$(this).css('column-span','');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.