Hello,

I am using .each along with custom data attributes in a jquery script.

I have run into a small issue.
I won't post the whole code on here but I will post a more simplified version.

Please do not criticize me on my hypothetical code, because I know some people love doing this

Here is my code:

Code JavaScript:
<div data-video-id="1"></div>
<div data-video-id="1"></div>
<div data-video-id="2"></div>
<div data-video-id="3"></div>
<div data-video-id="4"></div>
 
<script>
    $('div[data-video-id]').each(function(){
           videoid = $(this).attr('data-video-id');
 
        $(function() {
            alert(videoid);
        });      
    });
</script>

Ok, here is the problem. You see that alert? It is suppose to display an alert of every data-video-id.
The problem is that when the alert is INSIDE the function it displays only the first data-video-id and repeats it.

e.g It does the equivalent of this:

alert("1");
alert("1");
alert("1");
alert("1");

It works perfect when it isn't wrapped in the function, but I NEED it to be in the function.

This is what I need it to do:
alert("1");
alert("2");
alert("3");
alert("4");