sdfgg45 sdfgg45 - 1 year ago 77
Javascript Question

How to find a spesific class,and find a spesific element and add disabled attr to it

I have two buttons, one that votes no and one that votes yes, i need to disable both buttons after user have clicked.
I also want to add the color: grey to the button clicked.

So far im able to disable the one clicked but not the other one.

My code so far are:

The html code: (also runs in a loop, so there is increment on the id)

<div class="btn-group btn-group-justified">
<div class="btn-group">
<a href="#" data-id="yes" data-problem_id="1" class="problem_vote">
<button class="btn btn-no btn-vote">YES</button>
<div class="btn-group">
<a href="#" data-id="no" data-problem_id="2" class="problem_vote">
<button class="btn btn-no btn-vote">NO</button>

I have this jQuery code so far:

$('.problem_vote').on('click touchstart', function(e){

var link = this;



Answer Source

If you want to disable both at once, do this:

$('.problem_vote').on('click', function(e) {
    $(this).find("button").css('background-color', 'grey');
    $(this).closest(".btn-group-justified").find("a").attr('disabled', 'disabled');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download