Can I set a variable to match a value on javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can I set a variable to match a value on javascript

Let's say this function function pic1 (){ var carrete = document.getElementsByTagName('button'); pic = valueof button Would that work if button value is 1 on JavaScript?

9th Jan 2019, 1:47 AM
Alandec
4 Answers
+ 2
When dealing with buttons, they don't value, but they do have a property called innerText that might work, you better try it because I'm not really sure. Never tried it myself.
9th Jan 2019, 3:04 AM
voidneo
+ 2
Hi Alandec, Hope this give you more insight👍 https://code.sololearn.com/W67XhNStwZGr/?ref=app
9th Jan 2019, 3:57 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 1
Hi 🌴Vincent Berger🌴 ,thanks for your answer, it's a little advance for my level, I'm a beginner and just experimenting with function, what I'm trying to do is, I have an array with 5 images and 5 buttons,1for each images, therefore,I set 5 different function,1 per button,I was wondering if there's a way to do the same with one single function, here's the full code https://code.sololearn.com/WcLZQ5h6h848/?ref=app
9th Jan 2019, 11:41 AM
Alandec
+ 1
Alandec, To accomplish a toggle mechanism between 2 functions with 1 button click: https://www.sololearn.com/discuss/1543187/?ref=app To execute multiple functions with 1 button click you can assign the onclick element with multiple functions: onclick="one();two();three();" Have a look at the changes👍😊 https://code.sololearn.com/WgSeRCe57nBA/?ref=app
9th Jan 2019, 12:27 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar