How to get hidden span value using Javascript

Hello Developers, I have a question. Suppose I have an online store I brought items from database each item has a hidden Car like value. I would like to console.log ‘Car’ when I click on this div. Each div has same class name because I am using loop. Thank you

provide code on code pen or here

Please check this out.
https://zh2y0.csb.app/

I believe this will help you:
https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp

Nope. Suppose I have fetched a lot of query from Database now I want to print individual id from each query. How I will do that in javascript ?

I hope this example will help you:

JS code:

function test() {
  console.log("OUTPUT TO CONSOLE.LOG");
}

HTML code:

<div onClick="test()")>MY DIV</div>

At least it worked for me on jsbin.com when I was coding the snippet. If this not helps then try google or ask someone more experienced.