1

I have made a function with parameters but it doesn't work.

This is my code:

 function hideQuestion( _hideQuestion, _showQuestion){
   $('#_showQuestion').removeClass('hideOnInit');
   $('#_hideQuestion').addClass('hideOnInit');
   }

If I use the function like this

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion(question1, question2);' data-role='button'></a>

...nothing happens.

How can can I fix it?

0

3 Answers 3

16

You need to use the function parameter variables and you are using constant string instead. Also pass the ids from onclick as a stirng constant.

function hideQuestion( _hideQuestion, _showQuestion){
   $('#' + _showQuestion).removeClass('hideOnInit');
   $('#' + _hideQuestion).addClass('hideOnInit');
}

Change

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion(question1, question2);' data-role='button'></a>

To

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion("question1", "question2");' data-role='button'></a>

In javascript strings could be enclosed in single or double quotes and could be combined as we did on onclick

 onclick='hideQuestion("question1", "question2");' 
Sign up to request clarification or add additional context in comments.

Comments

0

you have a function and a parameter which is fine..but you have not used the parameter in your function... try this.

function hideQuestion( _hideQuestion, _showQuestion){
   $('#'+_showQuestion).removeClass('hideOnInit');  //using the set variable here...
   $('#'+_hideQuestion).addClass('hideOnInit');

}

and your html , yo need to pass the parameter.. here i am sending a string

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion("question1", "question2");' data-role='button'></a>  // sending thevariable to the functin as parameter

Comments

0

Adil's solution should work. Your issue is that with your code you are searching for the variables "#_showQuestion" and "#_hideQuestion" which you do not declare or are interested in finding

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.