Support » Plugins » Hacks » Add unique id to each inserted image – for jquery selection

  • Hello WordPress! Thanks in advance for the help. This community is amazing.

    I have a ‘Contact’ Page with users photos that uses jQuery. However, I had to insert ids into the tag for each image in order for jQuery to select them. I’m handing the site off to someone who is going to use the admin panel to change the images as employees come and go.

    BUT the admin panel inserts images without a unique id. So I can’t select them ‘out of the box’ with jQuery.

    see functionality here –

    Where should I go in the WordPress core to do this?


    Should I be going about this in another way?

Viewing 4 replies - 1 through 4 (of 4 total)
  • If they are always going to be in the same order like that



    then you can just refactor your JS to run off of indexes instead of ID’s. That way you can have an infinite number of elements and it will always work (as long as the ordering is consistent)

    Ah ok. By indexes you mean using parent child relationships and iterating through each one as long as they are in order?

    I think I could get that to work. Thanks for the advice!

    not parent child per se. Here is an example

    <div class='wrap'>

    jQuery(‘.wrap li’)
    returns all of those elements. just iterate through them like…

    jQuery('.wrap li').each(function(i){
    //do stuff


    Muchas Gracias!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add unique id to each inserted image – for jquery selection’ is closed to new replies.