Purpose = toggle a section 'more info' for a specific item in a list
Problem = a simple jQuery .toggle()
isn't working
Possible cause = getJSON loads to slow
I am loading a foursquare json to get venues around my current location. I then .append()
those venues with jQuery to my HTML. After that I have a function to toggle a section with 'more info' on a click-event.
After some searching I think I found the problem. My getJSON starts loading and then my next function is loaded in jQuery. After this next function is loaded (which is my .toggle()
) the getJSON finally finishes. So I think my function with my .toggle()
can't find the classes to toggle, because they are not yet in my HTML because my getJSON isn't finished loading the data.
Here is my jQuery code.
And the output of my console in my browser has this order:
loaded 4sq venues line 29
toggle function loaded line 33
200 line 10
It's because of this meta.code
on line 10 that I believe the getJSON is to slow loading...
I hope I made myself clear enough.
Thanks in advance
You should add your
click
event to body likeBecause you add elements dynamically!