Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

Could you point how to obtain an effect of choosed at a bootstrap card ?

Hi Experts


Could you point how to obtain an effect of choosed at a bootstrap card ?

Accordingly with:

User generated image
What I need is when a card is clicked its bottom part changes color and if possible a "check" symbol is presented.

Then a button at bottom left side is clicked to continues the process.
(I guess this is a Bottstrap button also)

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eduardo Fuerte

ASKER

Hi Chris

So did I, but I had no effects when a card is clicked.

<style>

.card { margin: 15px; }

.card.clicked {
    background-color: green;
}

</style>

Open in new window


<script>

	$('.card').click(function() {

		$('.card').removeClass('clicked'); // remove it from all other cards
		$(this).addClass('clicked');
		
		
		$('#CampaignID').val( $(this).data('campaignid') )
	})
	
   
</script>

Open in new window

Hey Eduardo,

Usually, when writing jQuery code (or any javascript code for that matter) we need to defer to firing of it until all the elements are loaded. In jQuery, we ddo this by wrapping it in a DOM Ready function, so just edit your code to do that:

<script>
$(function() {

    $('.card').click(function() {
        $('.card').removeClass('clicked'); // remove it from all other cards
        $(this).addClass('clicked');

        $('#CampaignID').val( $(this).data('campaignid') )
    });

});
</script>

Open in new window

I suspect that will solve your problem.
Hi Chris

So did I, but still not running.

Maybe something else is preventing it to run.

The cards:

       <div class="row no-gutters">
            	@foreach ($campaigns as $campaign)  
            	<div class="col-3">
            		<div class="card bg-light" data-campaignid="{{ $campaign->CampaignID }}">
            			<img src="/img/img_logo.png" class="img-fluid img-responsive">
            			<h5 class="card-title">{{ $campaign->CampaignID }} {{ $campaign->CampaignName }}</h5>
            		</div>
            	</div>
            	@endforeach
            </div>

Open in new window

Ahh right. You have the bg-light class on your card, which is a BootStrap class to change the background colour. That style rule is tagged with !important, so it's overriding your .clicked class.

You have a few options. You can remove the bg-light class from your card:

<div class="card" ...

You can set your own rule to be important:

.card.clicked { background-color: green !important; }

Or you can choose to style something within the card instead of the card itself:

<div class="card bg-light">
    <div class="wrapper">
        <h5>This is a card</h5>
    </div>
</div>

.card.clicked .wrapper { background-color: green; }

Any one of those solution will work, but they all have their pros and cons.
Just  removing bg-light class make it runs!
Chris

Thank you for the help!
No worries Eduardo. Glad you got it sorted :)