Dont know your markup, so just a guess: in case your element with this class is inside the `#+ idx + "_html"` element you could use a rooted selector, which is much faster

`$("#+" idx + "_html"`).find("." +idx+"_img").attr(.....)`