0

For my example I have 3 a href tags. So if I click on the first a href tag so I like to pop the first event_id from the array variable in the console. How can I to solve this?

Here my HTML code:

<a href="#" event-id="" class="event_delete">Link</a>
<a href="#" event-id="" class="event_delete">Link</a>
<a href="#" event-id="" class="event_delete">Link</a>

Here my jQuery code:

var event_id = new Array(); 
    //event_id for the first a href tag
    event_id.push("1X4JxCOwhDpD4Oj5ch");
    //event_id for the second a href tag
    event_id.push("LKb77tAmVzeJJjE83LH");
    //event_id for the third a href tag
    event_id.push("h0NTcpfUlinWbpwBbpB1");


jQuery('.event_delete').click(function(){
    var index = jQuery('.event_delete').index(this);
    //..
    //console.log(event_id.pop(???))

})

JSFIDDLE DEMO

1 Answer 1

2

It seems to me like you should associate the array IDs with the link's IDs

jQuery("a.event_delete").each( function(index, value){
    jQuery(this).attr('id', event_id[index]);
    console.log(this);
});

jQuery('.event_delete').click(function(){
    var index = jQuery('.event_delete').index(this);
    console.log(jQuery(this).attr('id'));
});

But you could just have the IDs in the HTML originally, unless you are getting them from another source later.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.