How to select elements based on partial id in jQuery
I had a bunch of images on a webpage that had id’s that began with myimage and then had a number, like myimage1, myimage2, myimage3. I wanted to select them all and change the image. To do this you can use 1 line of the code:
$('img[id*=myimage]').attr("src", "/images/differentimg.jpg");
In this code you are telling jQuery to look for any img tags on your webpage that have the word myimage in their id and then change the src tag of the image to differentimg.jpg.