0

I have a list which is generated so it can contain any amount of questions.

There are always three answers, "OK", "Fout" and "N.v.t."

When fout is selected (fout means wrong in dutch) a dropdown appears where additional info and an image can be added.

I made the same for OK which worked, but now I want to only show that dropdown when a plus icon is clicked. This icon only appears after a user answers a question with OK.

You can see it here: https://jsfiddle.net/6pxjskr5/

How can I do that? My guess is a click event inside a click event but I don't know if that is possible.

I tried the following:

$(document).on('click', '[id^=radio]', function(){
  var userresp = this.value;
  var fout_id = $(this).attr('id');
  var index = fout_id.split('-')[1];
  if (userresp == 'ok') index= parseInt(index)+ 1;
  if (userresp == 'fout') index= parseInt(index)+ 0;
  if (userresp == 'nvt') index= parseInt(index)- 1;
  // The container for the additional negative info (FOUT)
  var afw_id = 'afw-div-' + index;
  // The container for the additional positive info (OK)
  var pos_id = 'pos-div-' + index;
  // The plus icon
  var plus_id = 'plus-div-' + index;
    console.log('radio clicked', userresp, index);
    if (userresp=='fout') {
        $('#' + afw_id).slideDown();
        $('#' + pos_id).slideUp();
        $('#' + plus_id).hide();
    }
    else if(userresp=='ok'){
        $('#' + afw_id).slideUp();
        $('#' + plus_id).show();

        $(document).on('click', plus_id, function(){
          console.log('test');
        });
    }else{
        $('#' + plus_id).hide();
        $('#' + afw_id).slideUp();
        $('#' + pos_id).slideUp();
    }
});

But there is no test message in my console when clicking on the plus icon.

1 Answer 1

1

Your selector plus_id equals for example plus-div-123. But you intend to select by ID so it should be prefixed with a #. So it becomes: #plus-div-123.

Sign up to request clarification or add additional context in comments.

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.