Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  2] [ 3]  / answers: 1 / hits: 9504  / 11 Years ago, thu, december 19, 2013, 12:00:00

I am having problem with getting parameter from javascript onClick function



title = as
$('<li onClick=pushRight('+hello+') class=item></li>')


and my console log print this Uncaught SyntaxError: Unexpected token }


More From » jquery

 Answers
3
title = as
$('<li onClick=pushRight('+hello+') class=item></li>')


See the added double quotes. '+hello+' Also double quotes over your pushRight function.



Your code won't work because it render an invalid html as shown below.



<li onClick=pushRight(as) class=item></li>



See, there were no quotes before and after pushRight, also before and after your
string sa. Know the mistake and correct. Using inline js with html is not recommended.You have to bind events in these scenarios.



[#49387] Wednesday, December 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;