0

I'm setting up a quiz where I can choose the number of questions to be populated by php.

When the last question is cleared it displays a new content.

But I'd like to display it only when one of the button is clicked. Because the buttons are populated with php I can't use a custom ID. So I'd like to trigger an event (a popup window) if one of the button is click and stop the event that display the next content.

Unfortunatly I can't achieve this.

Tried to use event.propagation, but my knowledge in coding is so low I don't even know what I do.

$(document).on("click", "#q3a2", function newPopup(url) {
    popupWindow = window.open(
        "./gluck.html",'popUpWindow','height=10vh,width=auto,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
     });


if ($(".questionStep").length <= 0 ) {
        $("#Box1").hide();
        $("#NewContent").show();

    }


<div id="Box1" class="cearfix" style="">

 […]
            <article id="step3" class="questionStep clearfix" data-step="3" style="">
                <button onclick="scrollToTop()" class="stepButton yesBtn s3" data-step="3" id="q3a1">Yes</button>
                <button onclick="scrollToTop()" class="stepButton yesBtn s3" data-step="3" id="q3a2">No</button>
            </article>
        </div>

At the moment I can pop up the window but the newcontent is displayed. I'd like it to stay hidden until q3a1 is clicked.

Thanks

  • 1
    Assign the event handler to a class instead of IDs. If you're adding them dynamically, use [event delegation](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements). Then the event handler can check whether it's the last one or not. – Barmar May 06 '19 at 19:28
  • Ok I'll check that. I thought because the page was populated I could use the ID to get the event fired. – David Marmor May 07 '19 at 10:40
  • You said that you can't use a custom ID, I assumed that was because you're populating it dynamically. – Barmar May 07 '19 at 13:39

0 Answers0