1

I try to do like a questionnary, when you click on 1 answer, that check if it's the good answer and then desactivate the onclick event, after clicking on an other button to change the question and add new answer i want to reactivate the click but i dont know how to do this in javascript :/

Here the code for better explanation x):

<ol id="answerList" type="A">
      <img class="imgLine" src="" id="answer-a-img" /><li onclick="clickLine(this);" id="answer-a" ></li>
      <img class="imgLine" src="" id="answer-b-img" /><li onclick="clickLine(this);" id="answer-b" ></li>
      <img class="imgLine" src="" id="answer-c-img" /><li onclick="clickLine(this);" id="answer-c" ></li>
      <img class="imgLine" src="" id="answer-d-img" /><li onclick="clickLine(this);" id="answer-d" ></li>
</ol>

Here is the answer and the onclick event is working and that call clickLine function

I desactivated the onclick event by doing this: (i know it's not clean but i didnt saw an other way :/)

document.getElementById('answer-a').onclick = "";
document.getElementById('answer-b').onclick = "";
document.getElementById('answer-c').onclick = "";
document.getElementById('answer-d').onclick = "";

but now, when i got new datas, i dont success to reactivate onclickevent, i tried this:

document.getElementById('answer-a').onclick = "clickLine(this);";
document.getElementById('answer-b').onclick = "clickLine(this);";
document.getElementById('answer-c').onclick = "clickLine(this);";
document.getElementById('answer-d').onclick = "clickLine(this);";

but didnt worked :/

thanks !

ps: I can use Jquery if there is a solution in it ^^

2 Answers 2

1

Something like:

    $(".imgLine").click(function(event)
    {
         $('.imgLine').unbind();
         event.preventDefault();
    });

    $("a#activate").click(function(event)
    {
        $('.imgLine').bind();        
        event.preventDefault();
    });

Where a#activate denotes the next question button.

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

2 Comments

thanks for your answer but where come from the "a#activate" and "a#deactivate"? ^^', and doesn't bind need a function as parameter ? :s
I just used a#deactivate to denote the element you can click to deactivate. Give me a sec and I'll update the answer to tailor it for you abit more.
0
document.getElementById('answer-a').onclick = "javascript:clickLine(this);";
document.getElementById('answer-b').onclick = "javascript:clickLine(this);";
document.getElementById('answer-c').onclick = "javascript:clickLine(this);";
document.getElementById('answer-d').onclick = "javascript:clickLine(this);";

Try to Execute like this. First check do you have javascript:clickLine() function.

2 Comments

didn't worked and yes i have clickLine function: function clickLine(target) { // blabla code }
$('#answer-a').click(function(){ clickLine(this);}); Try to execute this.

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.