Passing arguments to answerTapped

1 view
Skip to first unread message

amrita

unread,
Feb 6, 2010, 2:51:43 AM2/6/10
to EDUC 176 Programming Lab
Hi,

Is there a another way to pass values to answerTapped() from the html
code other than using document.getElementById('id').value as the
argument ?

Thanks,
Amrita

Amrita Thakur (अम्रिता ठाकुर)

unread,
Feb 6, 2010, 3:04:42 AM2/6/10
to EDUC 176 Programming Lab
I think I might have figured it out.

Passing $('#answer-1').text() seems to work, so I think that is probably the way to go.

Thanks,
Amrita

Steve Marmon

unread,
Feb 6, 2010, 2:57:36 PM2/6/10
to EDUC 176 Programming Lab
Hi Amrita,

$('#answer-1').text() will give you the text inside the opening and
closing tags of #answer-1. For example, if your code looks like this:

<div id="answer-1">33</div>

then $('#answer-1').text() will return "33". This will give you the
answer directly, and that may be all you need to do.

Another option would be to pass in "1" as the argument to answerTapped
for #answer-1, "2" for #answer-2, etc. (For the former, your code
would look like onclick="answerTapped(1);"). In that case, you would
still need to call .text() from within your answerTapped() function to
retrieve the actual answer value.

Hope that helps,
Steve

On Feb 6, 12:04 am, Amrita Thakur (अम्रिता ठाकुर)

Reply all
Reply to author
Forward
0 new messages