Skip to content
Advertisement

Get closest element by id Jquery

I have js code that populate div with some html :

JavaScript

I need to get findingval by click on it and idvalue

I write this code :

JavaScript

Finding val is working great, but idavalue isn’t getting.

What I doing wrong?

Advertisement

Answer

The id attribute should be unique in the same document so please replace the duplicate ones by the common classes.

When you change all the duplicate ids by common classes you should use these classes on your JS code like :

JavaScript

Demo:

JavaScript
JavaScript
Advertisement