jQuery selector as a variable not working. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

jQuery selector as a variable not working.

I tried to put a variable at the place of a selector but it fires automatically without click function. What is the problem? https://code.sololearn.com/Wj9IxEiIiz80/?ref=app

22nd Mar 2018, 11:58 AM
Siddhant Singh
Siddhant Singh - avatar
6 Answers
+ 3
In the very 1st line you should use the click event instead of ready. If u use ready event the function will execute as soon as the window loads Use the click event handler to make the function execute when clicked https://code.sololearn.com/WZ7bod4Dp959/?ref=app
22nd Mar 2018, 12:31 PM
Akshat Vira
Akshat Vira - avatar
+ 3
Hey, I solved it ...just take a look https://code.sololearn.com/WGFmRF597APj/?ref=app
22nd Mar 2018, 6:06 PM
Akshat Vira
Akshat Vira - avatar
+ 2
I wanted the selector to be a variable ...
22nd Mar 2018, 6:07 PM
Siddhant Singh
Siddhant Singh - avatar
+ 1
@AkshatVira but it fires off when we click anywhere on the screen.
22nd Mar 2018, 5:38 PM
Siddhant Singh
Siddhant Singh - avatar
+ 1
I'll try to get a solution ...
22nd Mar 2018, 6:10 PM
Akshat Vira
Akshat Vira - avatar
+ 1
okay thank you
22nd Mar 2018, 6:11 PM
Siddhant Singh
Siddhant Singh - avatar