Skip to content
Advertisement

Dynamic ID with JQUERY functions

I have a problem with my JQUERY code. Here’s the code:

JavaScript

It takes correctly the total of times the .testimonio-popup div is appearing in the site, and the fadeIn action for .testimoniooverlay class works.

But the fadeIn action for #popup-[number] is not working. Any help why?

For further assistance, I attach the PHP code that makes the query:

JavaScript

Thank you! Frede

Advertisement

Answer

@Rory McCrossan is right (see comment). I’m not sure what goes wrong there, but I would suggest you change this logic:

JavaScript

to using classes and attributes:

JavaScript

And if you want to interact elements with different classes, add data attributes to them so you can find them when needed. Here is a simple example:

JavaScript

Demo here – 4 popups, working: jsfiddle

(Defining the same functions inside a while loop is generally a bad idea.)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement