Jquery ID Attribute Contains With Selector and Variable

Posted by User970008 on Stack Overflow See other posts from Stack Overflow or by User970008
Published on 2012-04-03T17:11:25Z Indexed on 2012/04/03 17:30 UTC
Read the original article Hit count: 258

Filed under:
|
|

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" />

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about selector