Olivbelle
Olivbelle

Reputation: 23

up and down arrow onclick

I Have created HTML and css for a button where I need a up and down arrow toggle based on click. I am fine with the HTML and CSS however not so good with using jQuery for this. Could anyone start me off on this? On click .js-custom-sleeve-option arrow should change up/down.

.js-custom-sleeve-option {
    width: auto;
    min-width: 3.8rem;
    height: 3rem;
    display: inline-block;
    border: 1px solid #d1cac5;
    background: #f7f7f7;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.js-arrow-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #233354;
    position: relative;
    left: 7px;
}

.js-arrow-up {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #233354;
    position: relative;
    left: 6px;
    bottom: 12px;
}
<div>
			<a class="js-custom-sleeve-option">
				<span class="js-arrow-down"></span>
			</a>
</div>

Upvotes: 0

Views: 10291

Answers (2)

prasanth
prasanth

Reputation: 22490

you could do with toggleClass() of jquery function

$('.js-custom-sleeve-option').click(function(){
$(this).children('span').toggleClass('js-arrow-down js-arrow-up')
})
.js-custom-sleeve-option {
    width: auto;
    min-width: 3.8rem;
    height: 3rem;
    display: inline-block;
    border: 1px solid #d1cac5;
    background: #f7f7f7;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.js-arrow-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #233354;
    position: relative;
    left: 7px;
}

.js-arrow-up {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #233354;
    position: relative;
    left: 6px;
    bottom: 12px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
			<a class="js-custom-sleeve-option">
				<span class="js-arrow-down"></span>
			</a>
</div>

Upvotes: 0

Faisal Mehmood Awan
Faisal Mehmood Awan

Reputation: 436

this will be something like this.. ofcourse you have to modify it according your needs

$(function(){
$(".js-custom-sleeve-option").on('click' , function(){
  this.find('span').removeClass('js-arrow-down').end().addClass('js-arrow-up');
});
});

Upvotes: 1

Related Questions