Skip to content
Advertisement

Collect Attribute values ​and display it in the DOM whit JavaScript

I am developing a website that contains a series of products, each block contains a certain product, when hovering the mouse I need the name of this product to appear,

However, the product name is stored through an ‘DATA’ attribute. for example:

data-legend-item = “White T-Shirt”

I need to collect the value of this data attribute and make it appear every time I hover over it.

Remembering that they are a collection of blocks so I need to collect them from all data-legend-items on the page.

ps: notice that I made a script that only collects this value only from the first blockthat contains a data-legend-item

[

JavaScript
JavaScript
JavaScript

]1

Advertisement

Answer

I prefer to hide and show using CSS put take a look at this this.

always use id names only once in html file

JavaScript
JavaScript
JavaScript
Advertisement