Jquery ID Attribute Contains With Selector and Variable
- by User970008
I would like to search for an image ID that contains a value AND a variable.
I need the below script to be something like $("[id*='MYVALUE'+x]") but that does not work.
for (x=0; x< imageList.length; x++)
{
var imageSRC = imageList[x];
//need this to be MYVALUE + the X val
//search for IDs that contain MYVALUE + X
$("[id*='MYVALUE']").attr('src', 'images/'+imageSRC);
};
<!-- These images are replaced with images from the array imageList-->
<img id="dkj958-MYVALUE0" src="images/imageplaceholder" />
<img id="mypage-MYVALUE1" src="images/imageplaceholder" />
<img id="onanotherpage-MYVALUE2-suffix" src="images/imageplaceholder" />