jQuery selector with variable
问题 I need to select all images whose filename contain a certain string (variable) using jQuery. I am using: var str='-out.'; $('img[src*='+str+']'). //do something It works but fires the following warning in Firefox: " Expected ']' to terminate attribute selector but found '.' " Would someone know how to avoid this warning ? Thank You 回答1: I think you need double quotes or single around the attribute value. Look at Jquery Docs for attr*="value" selector like this: $("img[src*='"+str+"']") OR $(